Filename | /usr/share/perl5/DateTime/Format/Builder/Parser/Regex.pm |
Statements | Executed 76 statements in 989µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 740µs | 1.08ms | BEGIN@73 | DateTime::Format::Builder::Parser::Regex::
10 | 1 | 1 | 152µs | 876µs | create_parser | DateTime::Format::Builder::Parser::Regex::
20 | 2 | 1 | 54µs | 54µs | __ANON__[:84] | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 33µs | 40µs | BEGIN@68 | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 17µs | 117µs | BEGIN@70 | DateTime::Format::Builder::Parser::Regex::
1 | 1 | 1 | 12µs | 57µs | BEGIN@69 | 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 | 54µs | 2 | 46µs | # spent 40µs (33+6) within DateTime::Format::Builder::Parser::Regex::BEGIN@68 which was called:
# once (33µs+6µs) by DateTime::Format::Builder::Parser::BEGIN@1.6 at line 68 # spent 40µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@68
# spent 6µs making 1 call to strict::import |
69 | 3 | 73µs | 2 | 103µs | # spent 57µs (12+45) within DateTime::Format::Builder::Parser::Regex::BEGIN@69 which was called:
# once (12µs+45µs) by DateTime::Format::Builder::Parser::BEGIN@1.6 at line 69 # spent 57µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@69
# spent 45µs making 1 call to vars::import |
70 | 3 | 45µs | 2 | 217µs | # spent 117µs (17+100) within DateTime::Format::Builder::Parser::Regex::BEGIN@70 which was called:
# once (17µs+100µs) by DateTime::Format::Builder::Parser::BEGIN@1.6 at line 70 # spent 117µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@70
# spent 100µs making 1 call to Exporter::import |
71 | |||||
72 | 1 | 800ns | $VERSION = '0.77'; | ||
73 | 3 | 551µs | 2 | 1.09ms | # spent 1.08ms (740µs+345µs) within DateTime::Format::Builder::Parser::Regex::BEGIN@73 which was called:
# once (740µs+345µs) by DateTime::Format::Builder::Parser::BEGIN@1.6 at line 73 # spent 1.08ms making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@73
# spent 4µs making 1 call to UNIVERSAL::import |
74 | 1 | 26µ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 | 84µs | # spent 54µ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 (30µs+0s) by Params::Validate::_validate at line 311 of DateTime/Format/Builder/Parser.pm, avg 3µs/call
# 10 times (25µs+0s) by Params::Validate::_validate at line 333 of DateTime/Format/Builder/Parser.pm, avg 2µ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 | 18µs | 1 | 20µs | ); # spent 20µ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 876µs (152+724) within DateTime::Format::Builder::Parser::Regex::create_parser which was called 10 times, avg 88µs/call:
# 10 times (152µs+724µs) by DateTime::Format::Builder::Parser::create_single_parser at line 334 of DateTime/Format/Builder/Parser.pm, avg 88µs/call | ||||
141 | 40 | 130µs | my ($self, %args) = @_; | ||
142 | $args{extra} ||= {}; | ||||
143 | 10 | 54µs | unless (ref $self) # spent 54µs making 10 calls to DateTime::Format::Builder::Parser::generic::new, avg 5µs/call | ||
144 | { | ||||
145 | $self = $self->new( %args ); | ||||
146 | } | ||||
147 | |||||
148 | # Create our parser | ||||
149 | return $self->generic_parser( | ||||
150 | 10 | 670µs | ( map { exists $args{$_} ? ( $_ => $args{$_} ) : () } qw( # spent 670µs making 10 calls to DateTime::Format::Builder::Parser::generic::generic_parser, avg 67µ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__ |