Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / PPI / Token / QuoteLike / Words.pm
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 use strict;
29 use PPI::Token::QuoteLike          ();
30 use PPI::Token::_QuoteEngine::Full ();
31
32 use vars qw{$VERSION @ISA};
33 BEGIN {
34         $VERSION = '1.206';
35         @ISA     = qw{
36                 PPI::Token::_QuoteEngine::Full
37                 PPI::Token::QuoteLike
38         };
39 }
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 16
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 END_PERL
69 my @expected = qw/ foo bar baz /;
70
71 isa_ok( $non_empty_list_document, 'PPI::Document' );
72 my $non_empty_list_tokens =
73         $non_empty_list_document->find('PPI::Token::QuoteLike::Words');
74 is(
75         scalar @{$non_empty_list_tokens},
76         2,
77         'Found expected non-empty word lists.',
78 );
79 foreach my $token ( @{$non_empty_list_tokens} ) {
80         my $literal = $token->literal;
81         is(
82                 $literal,
83                 scalar @expected,
84                 qq<Scalar context literal() returns the list for "$token">,
85         );
86         my @literal = $token->literal;
87         is( scalar @literal, scalar @expected, qq<Element count for "$token"> );
88         for (my $x = 0; $x < @expected; $x++) {
89                 is( $literal[$x], $expected[$x], qq<Element $x of "$token"> );
90         }
91 }
92
93 =end testing
94
95 =cut
96
97 sub literal {
98         my $self    = shift;
99         my $content = $self->content;
100         $content    = substr( $self->content, 3, length($content) - 4 );
101         return split ' ', $content;
102 }
103
104 1;
105
106 =pod
107
108 =head1 SUPPORT
109
110 See the L<support section|PPI/SUPPORT> in the main module.
111
112 =head1 AUTHOR
113
114 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
115
116 =head1 COPYRIGHT
117
118 Copyright 2001 - 2009 Adam Kennedy.
119
120 This program is free software; you can redistribute
121 it and/or modify it under the same terms as Perl itself.
122
123 The full text of the license can be found in the
124 LICENSE file included with this module.
125
126 =cut