Regexp/Token/CharClass/POSIX.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 66.6% 4 / 6 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 83.0% 44 / 53 CC 6 SCAR 12.0
CC
6
Cov
83%
__no_explanation
6.0
__PPIX_TOKENIZER__regexp
5.0
BEGIN
1.0
CRAP 3.3
« Regexp/Node/Range.pm ↑ Summary Regexp/Element.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Token::CharClass::POSIX - Represent a POSIX character class
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{ [[:alpha:]] }smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Token::CharClass::POSIX> is a
14 L<PPIx::Regexp::Token::CharClass|PPIx::Regexp::Token::CharClass>.
15  
16 C<PPIx::Regexp::Token::CharClass::POSIX> is the parent of
17 L<PPIx::Regexp::Token::CharClass::POSIX::Unknown|PPIx::Regexp::Token::CharClass::POSIX::Unknown>.
18  
19 =head1 DESCRIPTION
20  
21 This class represents a POSIX character class. It will only be
22 recognized within a character class.
23  
24 Note that collating symbols (e.g. C<[.ch.]>) and equivalence classes
25 (e.g. C<[=a=]>) are valid in the POSIX standard, but are not valid in
26 Perl regular expressions. These end up being represented by
27 L<PPIx::Regexp::Token::CharClass::POSIX::Unknown|PPIx::Regexp::Token::CharClass::POSIX::Unknown>,
28 and are considered a parse failure.
29  
30 =head1 METHODS
31  
32 This class provides the following public methods beyond those provided
33 by its superclass.
34  
35 =cut
36  
37 package PPIx::Regexp::Token::CharClass::POSIX;
38  
39 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 9 ▶use base qw{ PPIx::Regexp::Token::CharClass };
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
45 COOKIE_CLASS
46 COOKIE_REGEX_SET
47 MINIMUM_PERL
48 @CARP_NOT
49 9 };
50  
51 9 our $VERSION = '0.092';
52  
53 # Return true if the token can be quantified, and false otherwise
54 # sub can_be_quantified { return };
55  
56 ##=head2 is_case_sensitive
57 ##
58 ##This override of the superclass method of the same name returns true if
59 ##the character class is C<[:lower:]> or C<[:upper:]>, and false (but
60 ##defined) for all other POSIX character classes.
61 ##
62 ##=cut
63 ##
64 ##{
65 ## my %case_sensitive = map { $_ => 1 } qw{ [:lower:] [:upper:] };
66 ##
67 ## sub is_case_sensitive {
68 ## my ( $self ) = @_;
69 ## return $case_sensitive{ $self->content() } || 0;
70 ## }
71 ##}
72  
73 1 ▶sub perl_version_introduced {
Subroutine perl_version_introduced: called CC=1 SCAR=0.0
Pod documented
74 # my ( $self ) = @_;
75 1 return '5.006';
76 }
77  
78 {
79  
80 9 my %explanation = (
81 '[:alnum:]' => 'Any alphanumeric character',
82 '[:^alnum:]' => 'Anything but an alphanumeric character',
83 '[:alpha:]' => 'Any alphabetic',
84 '[:^alpha:]' => 'Anything but an alphabetic',
85 '[:ascii:]' => 'Any character in the ASCII character set',
86 '[:^ascii:]' => 'Anything but a character in the ASCII character set',
87 '[:blank:]' => 'A GNU extension, equal to a space or a horizontal tab ("\\t")',
88 '[:^blank:]' => 'A GNU extension, anything but a space or a horizontal tab ("\\t")',
89 '[:cntrl:]' => 'Any control character',
90 '[:^cntrl:]' => 'Anything but a control character',
91 '[:digit:]' => 'Any decimal digit',
92 '[:^digit:]' => 'Anything but a decimal digit',
93 '[:graph:]' => 'Any non-space printable character',
94 '[:^graph:]' => 'Anything but a non-space printable character',
95 '[:lower:]' => 'Any lowercase character',
96 '[:^lower:]' => 'Anything but a lowercase character',
97 '[:print:]' => 'Any printable character',
98 '[:^print:]' => 'Anything but a printable character',
99 '[:punct:]' => 'Any graphical character excluding "word" characters',
100 '[:^punct:]' => 'Anything but a graphical character excluding "word" characters',
101 '[:space:]' => 'Any whitespace character',
102 '[:^space:]' => 'Anything but a whitespace character',
103 '[:upper:]' => 'Any uppercase character',
104 '[:^upper:]' => 'Anything but an uppercase character',
105 '[:word:]' => 'A Perl extension, equivalent to "\\w"',
106 '[:^word:]' => 'A Perl extension, equivalent to "\\W"',
107 '[:xdigit:]' => 'Any hexadecimal digit',
108 '[:^xdigit:]' => 'Anything but a hexadecimal digit',
109 );
110  
111 28 ▶ sub __explanation {
Subroutine __explanation: called CC=1 SCAR=0.0
112 28 return \%explanation;
113 }
114  
115 0 ▶ sub __no_explanation {
Subroutine __no_explanation: not called CC=2 SCAR=17.9
116 0 my ( $self ) = @_;
117 0 local $_ = $self->content();
118 0 ▶ m/ \A \[ = ( . ) = \] \z /smx
Branch: 1 branch
BranchTrueFalseTotal
/ \A \[ = ( . ) = \] \z /msx and return "POSIX Character Equivalent (to '$1'; " . 'unimplemented in Perl)' 0 0 0
119 and return "POSIX Character Equivalent (to '$1'; " .
120 "unimplemented in Perl)";
121 0 return q<Unknown POSIX character class>;
122 }
123  
124 }
125  
126 {
127  
128 9 my %class = (
129 ':' => __PACKAGE__,
130 );
131  
132 1083 ▶ sub __PPIX_TOKENIZER__regexp {
Subroutine __PPIX_TOKENIZER__regexp: called CC=5 SCAR=16.1
133 1083 my ( undef, $tokenizer ) = @_; # Invocant, $character unused
134  
135 1083 ▶ $tokenizer->cookie( COOKIE_CLASS )
Branch: 1 branch
BranchTrueFalseTotal
$tokenizer->cookie("]") or $tokenizer->cookie("])") or return 146 937 1083
Condition100%3/3
$tokenizer->cookie("]") or $tokenizer->cookie("])")
l!l&&r!l&&!r
11729937
MC/DC100%2/2
$tokenizer->cookie("]") or $tokenizer->cookie("])")
$tokenizer->cookie("]") $tokenizer->cookie("])")
Truth table100%3/3
A or B
A= $tokenizer->cookie("]")B= $tokenizer->cookie("])")
ABresult
1X1
011
000
136 or $tokenizer->cookie( COOKIE_REGEX_SET )
137 or return;
138  
139 146 ▶ if ( my $accept = $tokenizer->find_regexp(
Branch: 1 branch
BranchTrueFalseTotal
if (my $accept = $tokenizer->find_regexp(qr/ \A [[] ( [.=:] ) \^? .*? \1 []] /msx)) 37 109 146
140 qr{ \A [[] ( [.=:] ) \^? .*? \1 []] }smx ) ) {
141 37 my ( $punc ) = $tokenizer->capture();
142 return $tokenizer->make_token( $accept,
143 37 ▶ $class{$punc} || __PACKAGE__ . '::Unknown' );
Condition50%1/2
$class{$punc} || 'PPIx::Regexp::Token::CharClass::POSIX::Unknown'
l!l
370
MC/DC0%0/1
$class{$punc} || 'PPIx::Regexp::Token::CharClass::POSIX::Unknown'
$class{$punc}
Truth table50%1/2
A
A= $class{$punc}
Aresult
11
00
144 }
145  
146 109 return;
147  
148 }
149  
150 }
151  
152 9 1;
153  
154 __END__
« Regexp/Node/Range.pm ↑ Summary Regexp/Element.pm »