| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Utilities/Statement.pm |
| Statements | Executed 17 statements in 554µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 470µs | 26.6ms | PPIx::Utilities::Statement::BEGIN@19 |
| 1 | 1 | 1 | 17µs | 17µs | PPIx::Utilities::Statement::BEGIN@10 |
| 1 | 1 | 1 | 10µs | 73µs | PPIx::Utilities::Statement::BEGIN@21 |
| 1 | 1 | 1 | 7µs | 26µs | PPIx::Utilities::Statement::BEGIN@16 |
| 1 | 1 | 1 | 7µs | 10µs | PPIx::Utilities::Statement::BEGIN@12 |
| 1 | 1 | 1 | 6µs | 18µs | PPIx::Utilities::Statement::BEGIN@11 |
| 0 | 0 | 0 | 0s | 0s | PPIx::Utilities::Statement::_get_constant_names_from_constant_pragma |
| 0 | 0 | 0 | 0s | 0s | PPIx::Utilities::Statement::get_constant_name_elements_from_declaring_statement |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ############################################################################## | ||||
| 2 | # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/PPIx-Utilities/lib/PPIx/Utilities/Statement.pm $ | ||||
| 3 | # $Date: 2010-11-13 14:25:12 -0600 (Sat, 13 Nov 2010) $ | ||||
| 4 | # $Author: clonezone $ | ||||
| 5 | # $Revision: 3990 $ | ||||
| 6 | ############################################################################## | ||||
| 7 | |||||
| 8 | package PPIx::Utilities::Statement; | ||||
| 9 | |||||
| 10 | 2 | 40µs | 1 | 17µs | # spent 17µs within PPIx::Utilities::Statement::BEGIN@10 which was called:
# once (17µs+0s) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 10 # spent 17µs making 1 call to PPIx::Utilities::Statement::BEGIN@10 |
| 11 | 2 | 18µs | 2 | 29µs | # spent 18µs (6+11) within PPIx::Utilities::Statement::BEGIN@11 which was called:
# once (6µs+11µs) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 11 # spent 18µs making 1 call to PPIx::Utilities::Statement::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 26µs | 2 | 14µs | # spent 10µs (7+4) within PPIx::Utilities::Statement::BEGIN@12 which was called:
# once (7µs+4µs) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 12 # spent 10µs making 1 call to PPIx::Utilities::Statement::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | |||||
| 14 | 1 | 700ns | our $VERSION = '1.001000'; | ||
| 15 | |||||
| 16 | 2 | 32µs | 2 | 45µs | # spent 26µs (7+19) within PPIx::Utilities::Statement::BEGIN@16 which was called:
# once (7µs+19µs) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 16 # spent 26µs making 1 call to PPIx::Utilities::Statement::BEGIN@16
# spent 19µs making 1 call to Exporter::import |
| 17 | |||||
| 18 | |||||
| 19 | 3 | 124µs | 2 | 26.6ms | # spent 26.6ms (470µs+26.1) within PPIx::Utilities::Statement::BEGIN@19 which was called:
# once (470µs+26.1ms) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 19 # spent 26.6ms making 1 call to PPIx::Utilities::Statement::BEGIN@19
# spent 12µs making 1 call to UNIVERSAL::VERSION |
| 20 | |||||
| 21 | 2 | 305µs | 2 | 136µs | # spent 73µs (10+63) within PPIx::Utilities::Statement::BEGIN@21 which was called:
# once (10µs+63µs) by Perl::Critic::Policy::NamingConventions::Capitalization::BEGIN@29 at line 21 # spent 73µs making 1 call to PPIx::Utilities::Statement::BEGIN@21
# spent 63µs making 1 call to base::import |
| 22 | |||||
| 23 | 1 | 800ns | our @EXPORT_OK = qw( | ||
| 24 | get_constant_name_elements_from_declaring_statement | ||||
| 25 | ); | ||||
| 26 | |||||
| 27 | |||||
| 28 | 1 | 3µs | 1 | 43µs | Readonly::Hash my %IS_COMMA => ( q[,] => 1, q[=>] => 1 ); # spent 43µs making 1 call to Readonly::Hash |
| 29 | |||||
| 30 | |||||
| 31 | sub get_constant_name_elements_from_declaring_statement { | ||||
| 32 | my ($element) = @_; | ||||
| 33 | |||||
| 34 | return if not $element; | ||||
| 35 | return if not $element->isa('PPI::Statement'); | ||||
| 36 | |||||
| 37 | if ( $element->isa('PPI::Statement::Include') ) { | ||||
| 38 | my $pragma; | ||||
| 39 | if ( $pragma = $element->pragma() and $pragma eq 'constant' ) { | ||||
| 40 | return _get_constant_names_from_constant_pragma($element); | ||||
| 41 | } # end if | ||||
| 42 | } elsif ( not $element->specialized() and $element->schildren() > 2 ) { | ||||
| 43 | my $supposed_constant_function = $element->schild(0)->content(); | ||||
| 44 | my $declaring_scope = $element->schild(1)->content(); | ||||
| 45 | |||||
| 46 | if ( | ||||
| 47 | ( | ||||
| 48 | $supposed_constant_function eq 'const' | ||||
| 49 | or $supposed_constant_function =~ m< \A Readonly \b >xms | ||||
| 50 | ) | ||||
| 51 | and ($declaring_scope eq 'our' or $declaring_scope eq 'my') | ||||
| 52 | ) { | ||||
| 53 | return $element->schild(2); | ||||
| 54 | } # end if | ||||
| 55 | } # end if | ||||
| 56 | |||||
| 57 | return; | ||||
| 58 | } # end get_constant_name_elements_from_declaring_statement() | ||||
| 59 | |||||
| 60 | |||||
| 61 | sub _get_constant_names_from_constant_pragma { | ||||
| 62 | my ($include) = @_; | ||||
| 63 | |||||
| 64 | my @arguments = $include->arguments() or return; | ||||
| 65 | |||||
| 66 | my $follower = $arguments[0]; | ||||
| 67 | return if not defined $follower; | ||||
| 68 | |||||
| 69 | # We test for a 'PPI::Structure::Block' in the following because some | ||||
| 70 | # versions of PPI parse the last element of 'use constant { ONE => 1, TWO | ||||
| 71 | # => 2 }' as a block rather than a constructor. As of PPI 1.206, PPI | ||||
| 72 | # handles the above correctly, but still blows it on 'use constant 1.16 { | ||||
| 73 | # ONE => 1, TWO => 2 }'. | ||||
| 74 | if ( | ||||
| 75 | $follower->isa( 'PPI::Structure::Constructor' ) | ||||
| 76 | or $follower->isa( 'PPI::Structure::Block' ) | ||||
| 77 | ) { | ||||
| 78 | my $statement = $follower->schild( 0 ) or return; | ||||
| 79 | $statement->isa( 'PPI::Statement' ) or return; | ||||
| 80 | |||||
| 81 | my @elements; | ||||
| 82 | my $inx = 0; | ||||
| 83 | foreach my $child ( $statement->schildren() ) { | ||||
| 84 | if (not $inx % 2) { | ||||
| 85 | push @{ $elements[ $inx ] ||= [] }, $child; | ||||
| 86 | } # end if | ||||
| 87 | |||||
| 88 | if ( $IS_COMMA{ $child->content() } ) { | ||||
| 89 | $inx++; | ||||
| 90 | } # end if | ||||
| 91 | } # end foreach | ||||
| 92 | |||||
| 93 | return map | ||||
| 94 | { | ||||
| 95 | ( | ||||
| 96 | $_ | ||||
| 97 | and @{$_} == 2 | ||||
| 98 | and '=>' eq $_->[1]->content() | ||||
| 99 | and $_->[0]->isa( 'PPI::Token::Word' ) | ||||
| 100 | ) | ||||
| 101 | ? $_->[0] | ||||
| 102 | : () | ||||
| 103 | } | ||||
| 104 | @elements; | ||||
| 105 | } else { | ||||
| 106 | return $follower; | ||||
| 107 | } # end if | ||||
| 108 | |||||
| 109 | return $follower; | ||||
| 110 | } # end _get_constant_names_from_constant_pragma() | ||||
| 111 | |||||
| 112 | |||||
| 113 | 1 | 4µs | 1; | ||
| 114 | |||||
| 115 | __END__ |