blib/lib/PPIx/Regexp/Support.pm

filter: Statementstmt 92.1% 35 / 38 Branchbran 61.1% 11 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 85.5% 59 / 69 CC 11 SCAR 10.9
CC
11
Cov
82%
encode
5.2
encode_available
3.1
__defined_or
3.0
CRAP 3.0
« blib/lib/PPIx/Regexp/Structure/Main.pm ↑ Summary blib/lib/PPIx/Regexp/Structure/Assertion.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Support - Basis for the PPIx::Regexp support classes
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{foo}smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Support> is not descended from any other class.
14  
15 C<PPIx::Regexp::Support> is the parent of
16 L<PPIx::Regexp::Dumper|PPIx::Regexp::Dumper>,
17 L<PPIx::Regexp::Lexer|PPIx::Regexp::Lexer> and
18 L<PPIx::Regexp::Tokenizer|PPIx::Regexp::Tokenizer>.
19  
20 =head1 DESCRIPTION
21  
22 This abstract class provides methods for the C<PPIx::Regexp> support
23 classes.
24  
25 =head1 METHODS
26  
27 This class provides the following public methods. Methods not documented
28 here are private, and unsupported in the sense that the author reserves
29 the right to change or remove them without notice.
30  
31 =cut
32  
33 package PPIx::Regexp::Support;
34  
35 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 9 ▶use PPIx::Regexp::Constant qw{ @CARP_NOT };
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use PPIx::Regexp::Util qw{ __instance };
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 9 our $VERSION = '0.091_01';
42  
43 =head2 close_bracket
44  
45 This method takes as its argument a character. If this character is an
46 open bracket the corresponding close bracket is returned. Otherwise
47 C<undef> is returned. Only the ASCII bracket characters are considered
48 brackets: (), {}, [], and <>.
49  
50 =cut
51  
52 {
53 9 my %bracket = (
54 '(' => ')',
55 '{' => '}',
56 '<' => '>',
57 '[' => ']',
58 );
59  
60 sub close_bracket {
61 705 ▶ my ( undef, $char ) = @_; # Invocant unused
Subroutine close_bracket: called CC=3 SCAR=11.0
Pod documented
62 705 ▶ defined $char or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $char or return 0 705 705
63 705 ▶ __instance( $char, 'PPIx::Regexp::Element' )
Branch: 1 branch
BranchTrueFalseTotal
__instance($char, "PPIx::Regexp::Element") and $char = $char->content 26 679 705
64 and $char = $char->content();
65 705 return $bracket{$char};
66 }
67  
68 }
69  
70 =head2 decode
71  
72 This method wraps the Encode::decode subroutine. If the object specifies
73 no encoding or encode_available() returns false, this method simply
74 returns its input string.
75  
76 =cut
77  
78 9 sub decode {
79 740 ▶ my ( $self, $data ) = @_;
Subroutine decode: called CC=3 SCAR=11.0
Pod documented
80 740 ▶ defined $self->{encoding} or return $data;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"encoding"} or return $data 739 1 740
81 1 ▶ encode_available() or return $data;
Branch: 1 branch
BranchTrueFalseTotal
encode_available() or return $data 0 1 1
82 1 return Encode::decode( $self->{encoding}, $data );
83 }
84  
85 =head2 encode
86  
87 This method wraps the Encode::encode subroutine. If the object specifies
88 no encoding or encode_available() returns false, this method simply
89 returns its input string.
90  
91 =cut
92  
93 sub encode {
94 51 ▶ my ( $self, $data ) = @_;
Subroutine encode: called CC=3 SCAR=16.5
Pod documented
95 51 ▶ defined $self->{encoding} or return $data;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"encoding"} or return $data 51 0 51
96 0 ▶ encode_available() or return $data;
Branch: 1 branch
BranchTrueFalseTotal
encode_available() or return $data 0 0 0
97 0 return Encode::encode( $self->{encoding}, $data );
98 }
99  
100 =head2 encode_available
101  
102 This method returns true if the Encode module is available, and false
103 otherwise. If it returns true, the Encode module has actually been
104 loaded.
105  
106 =cut
107  
108 {
109  
110 9 my $encode_available;
111  
112 sub encode_available {
113 1 ▶ defined $encode_available and return $encode_available;
Subroutine encode_available: called CC=3 SCAR=11.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $encode_available and return $encode_available 0 1 1
114 1 ▶ return ( $encode_available = eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; 1 } } ? : 1 0 1
115 1 require Encode;
116 1 1;
117 } ? 1 : 0
118 );
119 }
120  
121 }
122  
123 # This method is to be used only by the PPIx-Regexp package. It returns
124 # the first of its arguments which is defined. It will go away when
125 # (or if!) these modules get 'use 5.010;' at the top.
126  
127 9 sub __defined_or {
128 742 ▶ my ( undef, @args ) = @_; # Invocant unused
Subroutine __defined_or: called CC=3 SCAR=11.1
129 742 foreach my $arg ( @args ) {
130 2226 ▶ defined $arg and return $arg;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg and return $arg 742 1484 2226
131 }
132 0 return;
133 }
134  
135 9 1;
136  
137 __END__
« blib/lib/PPIx/Regexp/Structure/Main.pm ↑ Summary blib/lib/PPIx/Regexp/Structure/Assertion.pm »