File Coverage

blib/lib/PPIx/Utils/Language.pm
Criterion Covered Total %
statement 15 15 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 25 26 96.1


line stmt bran cond sub pod time code
1             package PPIx::Utils::Language;
2              
3 4     4   90660 use strict;
  4         13  
  4         94  
4 4     4   16 use warnings;
  4         6  
  4         88  
5 4     4   14 use Exporter 'import';
  4         6  
  4         1197  
6              
7             our $VERSION = '0.003';
8              
9             our @EXPORT_OK = qw(precedence_of symbol_without_sigil);
10              
11             our %EXPORT_TAGS = (all => [@EXPORT_OK]);
12              
13             # From Perl::Critic::Utils
14             my %PRECEDENCE_OF = (
15             '->' => 1,
16             '++' => 2,
17             '--' => 2,
18             '**' => 3,
19             '!' => 4,
20             '~' => 4,
21             '\\' => 4,
22             '=~' => 5,
23             '!~' => 5,
24             '*' => 6,
25             '/' => 6,
26             '%' => 6,
27             'x' => 6,
28             '+' => 7,
29             '-' => 7,
30             '.' => 7,
31             '<<' => 8,
32             '>>' => 8,
33             '-R' => 9,
34             '-W' => 9,
35             '-X' => 9,
36             '-r' => 9,
37             '-w' => 9,
38             '-x' => 9,
39             '-e' => 9,
40             '-O' => 9,
41             '-o' => 9,
42             '-z' => 9,
43             '-s' => 9,
44             '-M' => 9,
45             '-A' => 9,
46             '-C' => 9,
47             '-S' => 9,
48             '-c' => 9,
49             '-b' => 9,
50             '-f' => 9,
51             '-d' => 9,
52             '-p' => 9,
53             '-l' => 9,
54             '-u' => 9,
55             '-g' => 9,
56             '-k' => 9,
57             '-t' => 9,
58             '-T' => 9,
59             '-B' => 9,
60             '<' => 10,
61             '>' => 10,
62             '<=' => 10,
63             '>=' => 10,
64             'lt' => 10,
65             'gt' => 10,
66             'le' => 10,
67             'ge' => 10,
68             '==' => 11,
69             '!=' => 11,
70             '<=>' => 11,
71             'eq' => 11,
72             'ne' => 11,
73             'cmp' => 11,
74             '~~' => 11,
75             '&' => 12,
76             '|' => 13,
77             '^' => 13,
78             '&&' => 14,
79             '//' => 15,
80             '||' => 15,
81             '..' => 16,
82             '...' => 17,
83             '?' => 18,
84             ':' => 18,
85             '=' => 19,
86             '+=' => 19,
87             '-=' => 19,
88             '*=' => 19,
89             '/=' => 19,
90             '%=' => 19,
91             '||=' => 19,
92             '&&=' => 19,
93             '|=' => 19,
94             '&=' => 19,
95             '**=' => 19,
96             'x=' => 19,
97             '.=' => 19,
98             '^=' => 19,
99             '<<=' => 19,
100             '>>=' => 19,
101             '//=' => 19,
102             ',' => 20,
103             '=>' => 20,
104             'not' => 22,
105             'and' => 23,
106             'or' => 24,
107             'xor' => 24,
108             );
109              
110             sub precedence_of {
111 9     9 1 2672 my $elem = shift;
112 9 50       26 return undef if !$elem;
113 9 100       35 return $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem };
114             }
115             # End from Perl::Critic::Utils
116              
117             # From Perl::Critic::Utils::Perl
118             sub symbol_without_sigil {
119 6     6 1 2616 my ($symbol) = @_;
120              
121 6         23 (my $without_sigil = $symbol) =~ s< \A [\$@%*&] ><>x;
122              
123 6         21 return $without_sigil;
124             }
125             # End from Perl::Critic::Utils::Perl
126              
127             1;
128              
129             =head1 NAME
130              
131             PPIx::Utils::Language - Utility functions for PPI related to the Perl language
132              
133             =head1 SYNOPSIS
134              
135             use PPIx::Utils::Language ':all';
136              
137             =head1 DESCRIPTION
138              
139             This package is a component of L that contains functions
140             related to aspects of the Perl language.
141              
142             =head1 FUNCTIONS
143              
144             All functions can be imported by name, or with the tag C<:all>.
145              
146             =head2 precedence_of
147              
148             my $precedence = precedence_of($element);
149              
150             Given a L or a string, returns the precedence of
151             the operator, where 1 is the highest precedence. Returns undef if the
152             precedence can't be determined (which is usually because it is not an
153             operator).
154              
155             =head2 symbol_without_sigil
156              
157             my $name = symbol_without_sigil($symbol);
158              
159             Returns the name of the specified symbol with any sigil at the front.
160             The parameter can be a vanilla Perl string or a L.
161              
162             =head1 BUGS
163              
164             Report any issues on the public bugtracker.
165              
166             =head1 AUTHOR
167              
168             Dan Book
169              
170             Code originally from L by Jeffrey Ryan Thalhammer
171             and L by
172             Elliot Shank
173              
174             =head1 COPYRIGHT AND LICENSE
175              
176             This software is copyright (c) 2005-2011 Imaginative Software Systems,
177             2007-2011 Elliot Shank, 2017 Dan Book.
178              
179             This is free software; you can redistribute it and/or modify it under
180             the same terms as the Perl 5 programming language system itself.
181              
182             =head1 SEE ALSO
183              
184             L, L