| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/QuoteLike/Words.pm |
| Statements | Executed 11 statements in 176µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 12µs | 12µs | PPI::Token::QuoteLike::Words::BEGIN@33 |
| 1 | 1 | 1 | 11µs | 22µs | PPI::Token::QuoteLike::Words::BEGIN@28 |
| 1 | 1 | 1 | 6µs | 33µs | PPI::Token::QuoteLike::Words::BEGIN@32 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::QuoteLike::Words::BEGIN@29 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::QuoteLike::Words::BEGIN@30 |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::QuoteLike::Words::literal |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PPI::Token::QuoteLike::Words; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::Token::QuoteLike::Words - Word list constructor quote-like operator | ||||
| 8 | |||||
| 9 | =head1 INHERITANCE | ||||
| 10 | |||||
| 11 | PPI::Token::QuoteLike::Words | ||||
| 12 | isa PPI::Token::QuoteLike | ||||
| 13 | isa PPI::Token | ||||
| 14 | isa PPI::Element | ||||
| 15 | |||||
| 16 | =head1 DESCRIPTION | ||||
| 17 | |||||
| 18 | A C<PPI::Token::QuoteLike::Words> object represents a quote-like operator | ||||
| 19 | that acts as a constructor for a list of words. | ||||
| 20 | |||||
| 21 | # Create a list for a significant chunk of the alphabet | ||||
| 22 | my @list = qw{a b c d e f g h i j k l}; | ||||
| 23 | |||||
| 24 | =head1 METHODS | ||||
| 25 | |||||
| 26 | =cut | ||||
| 27 | |||||
| 28 | 2 | 18µs | 2 | 34µs | # spent 22µs (11+11) within PPI::Token::QuoteLike::Words::BEGIN@28 which was called:
# once (11µs+11µs) by PPI::Token::BEGIN@61 at line 28 # spent 22µs making 1 call to PPI::Token::QuoteLike::Words::BEGIN@28
# spent 11µs making 1 call to strict::import |
| 29 | 2 | 19µs | 1 | 3µs | # spent 3µs within PPI::Token::QuoteLike::Words::BEGIN@29 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@61 at line 29 # spent 3µs making 1 call to PPI::Token::QuoteLike::Words::BEGIN@29 |
| 30 | 2 | 17µs | 1 | 3µs | # spent 3µs within PPI::Token::QuoteLike::Words::BEGIN@30 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@61 at line 30 # spent 3µs making 1 call to PPI::Token::QuoteLike::Words::BEGIN@30 |
| 31 | |||||
| 32 | 2 | 32µs | 2 | 61µs | # spent 33µs (6+27) within PPI::Token::QuoteLike::Words::BEGIN@32 which was called:
# once (6µs+27µs) by PPI::Token::BEGIN@61 at line 32 # spent 33µs making 1 call to PPI::Token::QuoteLike::Words::BEGIN@32
# spent 27µs making 1 call to vars::import |
| 33 | # spent 12µs within PPI::Token::QuoteLike::Words::BEGIN@33 which was called:
# once (12µs+0s) by PPI::Token::BEGIN@61 at line 39 | ||||
| 34 | 1 | 300ns | $VERSION = '1.215'; | ||
| 35 | 1 | 13µs | @ISA = qw{ | ||
| 36 | PPI::Token::_QuoteEngine::Full | ||||
| 37 | PPI::Token::QuoteLike | ||||
| 38 | }; | ||||
| 39 | 1 | 76µs | 1 | 12µs | } # spent 12µs making 1 call to PPI::Token::QuoteLike::Words::BEGIN@33 |
| 40 | |||||
| 41 | =pod | ||||
| 42 | |||||
| 43 | =head2 literal | ||||
| 44 | |||||
| 45 | Returns the words contained. Note that this method does not check the | ||||
| 46 | context that the token is in; it always returns the list and not merely | ||||
| 47 | the last element if the token is in scalar context. | ||||
| 48 | |||||
| 49 | =begin testing literal 12 | ||||
| 50 | |||||
| 51 | my $empty_list_document = PPI::Document->new(\<<'END_PERL'); | ||||
| 52 | qw// | ||||
| 53 | qw/ / | ||||
| 54 | END_PERL | ||||
| 55 | |||||
| 56 | isa_ok( $empty_list_document, 'PPI::Document' ); | ||||
| 57 | my $empty_list_tokens = | ||||
| 58 | $empty_list_document->find('PPI::Token::QuoteLike::Words'); | ||||
| 59 | is( scalar @{$empty_list_tokens}, 2, 'Found expected empty word lists.' ); | ||||
| 60 | foreach my $token ( @{$empty_list_tokens} ) { | ||||
| 61 | my @literal = $token->literal; | ||||
| 62 | is( scalar @literal, 0, qq<No elements for "$token"> ); | ||||
| 63 | } | ||||
| 64 | |||||
| 65 | my $non_empty_list_document = PPI::Document->new(\<<'END_PERL'); | ||||
| 66 | qw/foo bar baz/ | ||||
| 67 | qw/ foo bar baz / | ||||
| 68 | qw {foo bar baz} | ||||
| 69 | END_PERL | ||||
| 70 | my @expected = qw/ foo bar baz /; | ||||
| 71 | |||||
| 72 | isa_ok( $non_empty_list_document, 'PPI::Document' ); | ||||
| 73 | my $non_empty_list_tokens = | ||||
| 74 | $non_empty_list_document->find('PPI::Token::QuoteLike::Words'); | ||||
| 75 | is( | ||||
| 76 | scalar(@$non_empty_list_tokens), | ||||
| 77 | 3, | ||||
| 78 | 'Found expected non-empty word lists.', | ||||
| 79 | ); | ||||
| 80 | foreach my $token ( @$non_empty_list_tokens ) { | ||||
| 81 | my $literal = $token->literal; | ||||
| 82 | is( | ||||
| 83 | $literal, | ||||
| 84 | scalar @expected, | ||||
| 85 | qq<Scalar context literal() returns the list for "$token">, | ||||
| 86 | ); | ||||
| 87 | my @literal = $token->literal; | ||||
| 88 | is_deeply( [ $token->literal ], \@expected, '->literal matches expected' ); | ||||
| 89 | } | ||||
| 90 | |||||
| 91 | =end testing | ||||
| 92 | |||||
| 93 | =cut | ||||
| 94 | |||||
| 95 | sub literal { | ||||
| 96 | my $self = shift; | ||||
| 97 | my $section = $self->{sections}->[0]; | ||||
| 98 | return split ' ', substr( | ||||
| 99 | $self->{content}, | ||||
| 100 | $section->{position}, | ||||
| 101 | $section->{size}, | ||||
| 102 | ); | ||||
| 103 | } | ||||
| 104 | |||||
| 105 | 1 | 2µs | 1; | ||
| 106 | |||||
| 107 | =pod | ||||
| 108 | |||||
| 109 | =head1 SUPPORT | ||||
| 110 | |||||
| 111 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 112 | |||||
| 113 | =head1 AUTHOR | ||||
| 114 | |||||
| 115 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
| 116 | |||||
| 117 | =head1 COPYRIGHT | ||||
| 118 | |||||
| 119 | Copyright 2001 - 2011 Adam Kennedy. | ||||
| 120 | |||||
| 121 | This program is free software; you can redistribute | ||||
| 122 | it and/or modify it under the same terms as Perl itself. | ||||
| 123 | |||||
| 124 | The full text of the license can be found in the | ||||
| 125 | LICENSE file included with this module. | ||||
| 126 | |||||
| 127 | =cut |