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 65     65   361 use strict;
  65         101  
  65         1477  
33 65     65   302 use PPI::Token ();
  65         100  
  65         9380  
34              
35             our $VERSION = '1.276';
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 1019     1019   1410 my $t = $_[1];
56 1019         2042 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
57              
58             # Are we still an operator if we add the next character
59 1019         1545 my $content = $t->{token}->{content};
60 1019 100       2557 return 1 if $POSTFIX{ $content . $char };
61              
62 1018         1855 $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