File Coverage

blib/lib/PPI/Token/Cast.pm
Criterion Covered Total %
statement 11 11 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package PPI::Token::Cast;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PPI::Token::Cast - A prefix which forces a value into a different context
8              
9             =head1 INHERITANCE
10              
11             PPI::Token::Cast
12             isa PPI::Token
13             isa PPI::Element
14              
15             =head1 DESCRIPTION
16              
17             A "cast" in PPI terms is one of more characters used as a prefix which force
18             a value into a different class or context.
19              
20             This includes referencing, dereferencing, and a few other minor cases.
21              
22             For expressions such as C<@$foo> or C<@{ $foo{bar} }> the C<@> in both cases
23             represents a cast. In this case, an array dereference.
24              
25             =head1 METHODS
26              
27             There are no additional methods beyond those provided by the parent
28             L and L classes.
29              
30             =cut
31              
32 64     64   355 use strict;
  64         113  
  64         1417  
33 64     64   264 use PPI::Token ();
  64         97  
  64         9177  
34              
35             our $VERSION = '1.275';
36              
37             our @ISA = "PPI::Token";
38              
39             our %POSTFIX = map { $_ => 1 } (
40             qw{
41             %* @* $*
42             },
43             '$#*' # throws warnings if it's inside a qw
44             );
45              
46              
47              
48              
49             #####################################################################
50             # Tokenizer Methods
51              
52             # A cast is either % @ $ or $#
53             # and also postfix dereference are %* @* $* $#*
54             sub __TOKENIZER__on_char {
55 1018     1018   1315 my $t = $_[1];
56 1018         1650 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
57              
58             # Are we still an operator if we add the next character
59 1018         1585 my $content = $t->{token}->{content};
60 1018 100       2160 return 1 if $POSTFIX{ $content . $char };
61              
62 1017         1817 $t->_finalize_token->__TOKENIZER__on_char( $t );
63             }
64              
65             1;
66              
67             =pod
68              
69             =head1 SUPPORT
70              
71             See the L in the main module.
72              
73             =head1 AUTHOR
74              
75             Adam Kennedy Eadamk@cpan.orgE
76              
77             =head1 COPYRIGHT
78              
79             Copyright 2001 - 2011 Adam Kennedy.
80              
81             This program is free software; you can redistribute
82             it and/or modify it under the same terms as Perl itself.
83              
84             The full text of the license can be found in the
85             LICENSE file included with this module.
86              
87             =cut