Filename | /usr/share/perl5/DateTime/Format/Builder/Parser/Regex.pm |
Statements | Executed 76 statements in 935µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 659µs | 899µs | BEGIN@73 | DateTime::Format::Builder::Parser::Regex::
10 | 1 | 1 | 165µs | 966µs | create_parser | DateTime::Format::Builder::Parser::Regex::
20 | 2 | 1 | 62µs | 62µs | __ANON__[:84] | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 31µs | 38µs | BEGIN@68 | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 18µs | 95µs | BEGIN@69 | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 14µs | 77µs | BEGIN@70 | DateTime::Format::Builder::Parser::Regex::
0 | 0 | 0 | 0s | 0s | __ANON__[:98] | DateTime::Format::Builder::Parser::Regex::
0 | 0 | 0 | 0s | 0s | do_match | DateTime::Format::Builder::Parser::Regex::
0 | 0 | 0 | 0s | 0s | make | DateTime::Format::Builder::Parser::Regex::
0 | 0 | 0 | 0s | 0s | post_match | DateTime::Format::Builder::Parser::Regex::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::Format::Builder::Parser::Regex; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
- - | |||||
68 | 3 | 60µs | 2 | 44µs | # spent 38µs (31+7) within DateTime::Format::Builder::Parser::Regex::BEGIN@68 which was called:
# once (31µs+7µs) by DateTime::Format::Builder::Parser::BEGIN@1.4 at line 68 # spent 38µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@68
# spent 7µs making 1 call to strict::import |
69 | 3 | 58µs | 2 | 172µs | # spent 95µs (18+77) within DateTime::Format::Builder::Parser::Regex::BEGIN@69 which was called:
# once (18µs+77µs) by DateTime::Format::Builder::Parser::BEGIN@1.4 at line 69 # spent 95µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@69
# spent 77µs making 1 call to vars::import |
70 | 3 | 41µs | 2 | 140µs | # spent 77µs (14+63) within DateTime::Format::Builder::Parser::Regex::BEGIN@70 which was called:
# once (14µs+63µs) by DateTime::Format::Builder::Parser::BEGIN@1.4 at line 70 # spent 77µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@70
# spent 64µs making 1 call to Exporter::import |
71 | |||||
72 | 1 | 800ns | $VERSION = '0.77'; | ||
73 | 3 | 508µs | 1 | 899µs | # spent 899µs (659+239) within DateTime::Format::Builder::Parser::Regex::BEGIN@73 which was called:
# once (659µs+239µs) by DateTime::Format::Builder::Parser::BEGIN@1.4 at line 73 # spent 899µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@73 |
74 | 1 | 11µs | @ISA = qw( DateTime::Format::Builder::Parser::generic ); | ||
75 | |||||
76 | __PACKAGE__->valid_params( | ||||
77 | # How to match | ||||
78 | params => { | ||||
79 | type => ARRAYREF, # mapping $1,$2,... to new() args | ||||
80 | }, | ||||
81 | regex => { | ||||
82 | type => SCALARREF, | ||||
83 | callbacks => { | ||||
84 | 20 | 92µs | # spent 62µs within DateTime::Format::Builder::Parser::Regex::__ANON__[/usr/share/perl5/DateTime/Format/Builder/Parser/Regex.pm:84] which was called 20 times, avg 3µs/call:
# 10 times (32µs+0s) by Params::Validate::_validate at line 333 of DateTime/Format/Builder/Parser.pm, avg 3µs/call
# 10 times (31µs+0s) by Params::Validate::_validate at line 311 of DateTime/Format/Builder/Parser.pm, avg 3µs/call | ||
85 | } | ||||
86 | }, | ||||
87 | # How to create | ||||
88 | extra => { | ||||
89 | type => HASHREF, | ||||
90 | optional => 1, | ||||
91 | }, | ||||
92 | constructor => { | ||||
93 | type => CODEREF|ARRAYREF, | ||||
94 | optional => 1, | ||||
95 | callbacks => { | ||||
96 | 'array has 2 elements' => sub { | ||||
97 | ref($_[0]) eq 'ARRAY' ? (@{$_[0]} == 2) : 1 | ||||
98 | } | ||||
99 | } | ||||
100 | }, | ||||
101 | 1 | 16µs | 1 | 22µs | ); # spent 22µs making 1 call to DateTime::Format::Builder::Parser::valid_params |
102 | |||||
103 | sub do_match | ||||
104 | { | ||||
105 | my $self = shift; | ||||
106 | my $date = shift; | ||||
107 | my @matches = $date =~ $self->{regex}; | ||||
108 | return @matches ? \@matches : undef; | ||||
109 | } | ||||
110 | |||||
111 | sub post_match | ||||
112 | { | ||||
113 | my $self = shift; | ||||
114 | my ( $date, $matches, $p ) = @_; | ||||
115 | # Fill %p from match | ||||
116 | @{$p}{ @{ $self->{params} } } = @$matches; | ||||
117 | return; | ||||
118 | } | ||||
119 | |||||
120 | sub make { | ||||
121 | my $self = shift; | ||||
122 | my ( $date, $dt, $p ) = @_; | ||||
123 | my @args = ( %$p, %{ $self->{extra} } ); | ||||
124 | if (my $cons = $self->{constructor}) | ||||
125 | { | ||||
126 | if (ref $cons eq 'ARRAY') { | ||||
127 | my ($class, $method) = @$cons; | ||||
128 | return $class->$method(@args); | ||||
129 | } elsif (ref $cons eq 'CODE') { | ||||
130 | return $self->$cons( @args ); | ||||
131 | } | ||||
132 | } | ||||
133 | else | ||||
134 | { | ||||
135 | return DateTime->new(@args); | ||||
136 | } | ||||
137 | } | ||||
138 | |||||
139 | sub create_parser | ||||
140 | # spent 966µs (165+800) within DateTime::Format::Builder::Parser::Regex::create_parser which was called 10 times, avg 97µs/call:
# 10 times (165µs+800µs) by DateTime::Format::Builder::Parser::create_single_parser at line 334 of DateTime/Format/Builder/Parser.pm, avg 97µs/call | ||||
141 | 40 | 141µs | my ($self, %args) = @_; | ||
142 | $args{extra} ||= {}; | ||||
143 | 10 | 56µs | unless (ref $self) # spent 56µs making 10 calls to DateTime::Format::Builder::Parser::generic::new, avg 6µs/call | ||
144 | { | ||||
145 | $self = $self->new( %args ); | ||||
146 | } | ||||
147 | |||||
148 | # Create our parser | ||||
149 | return $self->generic_parser( | ||||
150 | 10 | 744µs | ( map { exists $args{$_} ? ( $_ => $args{$_} ) : () } qw( # spent 744µs making 10 calls to DateTime::Format::Builder::Parser::generic::generic_parser, avg 74µs/call | ||
151 | on_match on_fail preprocess postprocess | ||||
152 | ) ), | ||||
153 | label => $args{label}, | ||||
154 | ); | ||||
155 | } | ||||
156 | |||||
157 | |||||
158 | 1 | 8µs | 1; | ||
159 | |||||
160 | __END__ |