| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPIx/Regexp/Support.pm |
| Statements | Executed 12 statements in 290µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 14µs | 25µs | PPIx::Regexp::Support::BEGIN@35 |
| 1 | 1 | 1 | 8µs | 12µs | PPIx::Regexp::Support::BEGIN@36 |
| 1 | 1 | 1 | 7µs | 28µs | PPIx::Regexp::Support::BEGIN@38 |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Support::_defined_or |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Support::close_bracket |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Support::decode |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Support::encode |
| 0 | 0 | 0 | 0s | 0s | PPIx::Regexp::Support::encode_available |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 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 | 2 | 24µs | 2 | 36µ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 # spent 25µs making 1 call to PPIx::Regexp::Support::BEGIN@35
# spent 12µs making 1 call to strict::import |
| 36 | 2 | 20µs | 2 | 16µ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 # spent 12µs making 1 call to PPIx::Regexp::Support::BEGIN@36
# spent 4µs making 1 call to warnings::import |
| 37 | |||||
| 38 | 2 | 228µs | 2 | 49µ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 # spent 28µs making 1 call to PPIx::Regexp::Support::BEGIN@38
# spent 21µs making 1 call to Exporter::import |
| 39 | |||||
| 40 | 1 | 600ns | our $VERSION = '0.036'; | ||
| 41 | |||||
| 42 | =head2 close_bracket | ||||
| 43 | |||||
| 44 | This method takes as its argument a character. If this character is an | ||||
| 45 | open bracket the corresponding close bracket is returned. Otherwise | ||||
| 46 | C<undef> is returned. Only the ASCII bracket characters are considered | ||||
| 47 | brackets: (), {}, [], and <>. | ||||
| 48 | |||||
| 49 | =cut | ||||
| 50 | |||||
| 51 | { | ||||
| 52 | 2 | 3µ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 | |||||
| 71 | This method wraps the Encode::decode subroutine. If the object specifies | ||||
| 72 | no encoding or encode_available() returns false, this method simply | ||||
| 73 | returns its input string. | ||||
| 74 | |||||
| 75 | =cut | ||||
| 76 | |||||
| 77 | sub 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 | |||||
| 86 | This method wraps the Encode::encode subroutine. If the object specifies | ||||
| 87 | no encoding or encode_available() returns false, this method simply | ||||
| 88 | returns its input string. | ||||
| 89 | |||||
| 90 | =cut | ||||
| 91 | |||||
| 92 | sub 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 | |||||
| 101 | This method returns true if the Encode module is available, and false | ||||
| 102 | otherwise. If it returns true, the Encode module has actually been | ||||
| 103 | loaded. | ||||
| 104 | |||||
| 105 | =cut | ||||
| 106 | |||||
| 107 | { | ||||
| 108 | |||||
| 109 | 2 | 200ns | 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 | |||||
| 126 | sub _defined_or { | ||||
| 127 | my ( $self, @args ) = @_; | ||||
| 128 | foreach my $arg ( @args ) { | ||||
| 129 | defined $arg and return $arg; | ||||
| 130 | } | ||||
| 131 | return; | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | 1 | 14µs | 1; | ||
| 135 | |||||
| 136 | __END__ |