← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:13 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Support.pm
StatementsExecuted 12 statements in 290µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11114µs25µsPPIx::Regexp::Support::::BEGIN@35PPIx::Regexp::Support::BEGIN@35
1118µs12µsPPIx::Regexp::Support::::BEGIN@36PPIx::Regexp::Support::BEGIN@36
1117µs28µsPPIx::Regexp::Support::::BEGIN@38PPIx::Regexp::Support::BEGIN@38
0000s0sPPIx::Regexp::Support::::_defined_orPPIx::Regexp::Support::_defined_or
0000s0sPPIx::Regexp::Support::::close_bracketPPIx::Regexp::Support::close_bracket
0000s0sPPIx::Regexp::Support::::decodePPIx::Regexp::Support::decode
0000s0sPPIx::Regexp::Support::::encodePPIx::Regexp::Support::encode
0000s0sPPIx::Regexp::Support::::encode_availablePPIx::Regexp::Support::encode_available
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=head1 NAME
2
3PPIx::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
13C<PPIx::Regexp::Support> is not descended from any other class.
14
15C<PPIx::Regexp::Support> is the parent of
16L<PPIx::Regexp::Dumper|PPIx::Regexp::Dumper>,
17L<PPIx::Regexp::Lexer|PPIx::Regexp::Lexer> and
18L<PPIx::Regexp::Tokenizer|PPIx::Regexp::Tokenizer>.
19
20=head1 DESCRIPTION
21
22This abstract class provides methods for the C<PPIx::Regexp> support
23classes.
24
25=head1 METHODS
26
27This class provides the following public methods. Methods not documented
28here are private, and unsupported in the sense that the author reserves
29the right to change or remove them without notice.
30
31=cut
32
33package PPIx::Regexp::Support;
34
35224µs236µs
# spent 25µs (14+12) within PPIx::Regexp::Support::BEGIN@35 which was called: # once (14µs+12µs) by base::import at line 35
use strict;
# spent 25µs making 1 call to PPIx::Regexp::Support::BEGIN@35 # spent 12µs making 1 call to strict::import
36220µs216µs
# spent 12µs (8+4) within PPIx::Regexp::Support::BEGIN@36 which was called: # once (8µs+4µs) by base::import at line 36
use warnings;
# spent 12µs making 1 call to PPIx::Regexp::Support::BEGIN@36 # spent 4µs making 1 call to warnings::import
37
382228µs249µs
# spent 28µs (7+21) within PPIx::Regexp::Support::BEGIN@38 which was called: # once (7µs+21µs) by base::import at line 38
use PPIx::Regexp::Util qw{ __instance };
# spent 28µs making 1 call to PPIx::Regexp::Support::BEGIN@38 # spent 21µs making 1 call to Exporter::import
39
401600nsour $VERSION = '0.036';
41
42=head2 close_bracket
43
44This method takes as its argument a character. If this character is an
45open bracket the corresponding close bracket is returned. Otherwise
46C<undef> is returned. Only the ASCII bracket characters are considered
47brackets: (), {}, [], and <>.
48
49=cut
50
51{
5223µs my %bracket = (
53 '(' => ')',
54 '{' => '}',
55 '<' => '>',
56 '[' => ']',
57 );
58
59 sub close_bracket {
60 my ( $self, $char ) = @_;
61 defined $char or return;
62 __instance( $char, 'PPIx::Regexp::Element' )
63 and $char = $char->content();
64 return $bracket{$char};
65 }
66
67}
68
69=head2 decode
70
71This method wraps the Encode::decode subroutine. If the object specifies
72no encoding or encode_available() returns false, this method simply
73returns its input string.
74
75=cut
76
77sub decode {
78 my ( $self, $data ) = @_;
79 defined $self->{encoding} or return $data;
80 encode_available() or return $data;
81 return Encode::decode( $self->{encoding}, $data );
82}
83
84=head2 encode
85
86This method wraps the Encode::encode subroutine. If the object specifies
87no encoding or encode_available() returns false, this method simply
88returns its input string.
89
90=cut
91
92sub encode {
93 my ( $self, $data ) = @_;
94 defined $self->{encoding} or return $data;
95 encode_available() or return $data;
96 return Encode::encode( $self->{encoding}, $data );
97}
98
99=head2 encode_available
100
101This method returns true if the Encode module is available, and false
102otherwise. If it returns true, the Encode module has actually been
103loaded.
104
105=cut
106
107{
108
1092200ns my $encode_available;
110
111 sub encode_available {
112 defined $encode_available and return $encode_available;
113 return ( $encode_available = eval {
114 require Encode;
115 1;
116 } ? 1 : 0
117 );
118 }
119
120}
121
122# This method is to be used only by the PPIx::Regexp package. It returns
123# the first of its arguments which is defined. It will go away when
124# (or if!) these modules get 'use 5.010;' at the top.
125
126sub _defined_or {
127 my ( $self, @args ) = @_;
128 foreach my $arg ( @args ) {
129 defined $arg and return $arg;
130 }
131 return;
132}
133
134114µs1;
135
136__END__