Filename | /home/lbr/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/Petal/Tiny.pm |
Statements | Executed 2158861 statements in 3.43s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
87930 | 3 | 1 | 889ms | 1.58s | tag_open | Petal::Tiny::
4170 | 4 | 1 | 553ms | 3.43s | makeitso (recurses: max depth 48, inclusive time 38.8s) | Petal::Tiny::
82550 | 2 | 1 | 512ms | 548ms | tag_close | Petal::Tiny::
23290 | 2 | 1 | 448ms | 685ms | extract_attributes | Petal::Tiny::
712230 | 16 | 1 | 275ms | 275ms | CORE:match (opcode) | Petal::Tiny::
4950 | 3 | 1 | 107ms | 163ms | resolve (recurses: max depth 1, inclusive time 64.3ms) | Petal::Tiny::
9330 | 7 | 1 | 90.1ms | 105ms | trim | Petal::Tiny::
128940 | 22 | 1 | 87.1ms | 87.1ms | CORE:subst (opcode) | Petal::Tiny::
7700 | 2 | 1 | 82.3ms | 151ms | tag_self_close | Petal::Tiny::
3070 | 1 | 1 | 77.3ms | 2.97s | makeitso_block (recurses: max depth 11, inclusive time 12.5s) | Petal::Tiny::
3070 | 1 | 1 | 46.0ms | 54.9ms | has_instructions | Petal::Tiny::
3070 | 1 | 1 | 41.8ms | 43.4ms | namespace | Petal::Tiny::
65402 | 7 | 1 | 40.3ms | 40.3ms | CORE:regcomp (opcode) | Petal::Tiny::
2190 | 6 | 1 | 25.7ms | 230ms | resolve_expression | Petal::Tiny::
1520 | 2 | 1 | 22.6ms | 25.5ms | node2tag | Petal::Tiny::
3870 | 1 | 1 | 20.6ms | 22.2ms | _interpolate_dollar | Petal::Tiny::
1500 | 1 | 1 | 19.5ms | 1.58s | tal_attributes (recurses: max depth 4, inclusive time 3.03s) | Petal::Tiny::
1680 | 1 | 1 | 16.4ms | 1.64s | tal_condition (recurses: max depth 4, inclusive time 3.13s) | Petal::Tiny::
1550 | 2 | 1 | 14.9ms | 1.60s | tal_content (recurses: max depth 4, inclusive time 3.11s) | Petal::Tiny::
1500 | 2 | 1 | 10.7ms | 1.56s | tal_omit_tag (recurses: max depth 4, inclusive time 2.88s) | Petal::Tiny::
1680 | 1 | 1 | 10.3ms | 1.64s | tal_define (recurses: max depth 4, inclusive time 3.14s) | Petal::Tiny::
2150 | 1 | 1 | 8.28ms | 9.60ms | xmlencode | Petal::Tiny::
1680 | 1 | 1 | 6.90ms | 1.65s | tal_on_error (recurses: max depth 4, inclusive time 3.14s) | Petal::Tiny::
8250 | 3 | 1 | 6.65ms | 6.65ms | reftype | Petal::Tiny::
1550 | 2 | 1 | 5.28ms | 1.58s | tal_replace (recurses: max depth 4, inclusive time 3.04s) | Petal::Tiny::
1550 | 2 | 1 | 4.79ms | 1.60s | tal_repeat (recurses: max depth 4, inclusive time 3.12s) | Petal::Tiny::
1 | 1 | 1 | 3.25ms | 3.54ms | BEGIN@5 | Petal::Tiny::
1 | 1 | 1 | 1.69ms | 1.72ms | BEGIN@3 | Petal::Tiny::
210 | 2 | 1 | 723µs | 11.2ms | modifier_true | Petal::Tiny::
50 | 1 | 1 | 473µs | 625µs | new | Petal::Tiny::
50 | 1 | 1 | 463µs | 3.43s | process | Petal::Tiny::
10 | 1 | 1 | 303µs | 1.96ms | _do_repeat | Petal::Tiny::
80 | 1 | 1 | 285µs | 2.50ms | modifier_false | Petal::Tiny::
1 | 1 | 1 | 217µs | 247µs | BEGIN@4 | Petal::Tiny::
10 | 1 | 1 | 80µs | 738µs | __ANON__[:133] | Petal::Tiny::
20 | 1 | 1 | 18µs | 18µs | CORE:substcont (opcode) | Petal::Tiny::
2 | 2 | 1 | 3µs | 3µs | CORE:qr (opcode) | Petal::Tiny::
0 | 0 | 0 | 0s | 0s | modifier_string | Petal::Tiny::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Petal::Tiny; | ||||
2 | 1 | 500ns | $Petal::Tiny::VERSION = '1.13'; | ||
3 | 2 | 1.62ms | 2 | 1.73ms | # spent 1.72ms (1.69+35µs) within Petal::Tiny::BEGIN@3 which was called:
# once (1.69ms+35µs) by main::BEGIN@2 at line 3 # spent 1.72ms making 1 call to Petal::Tiny::BEGIN@3
# spent 6µs making 1 call to warnings::import |
4 | 2 | 232µs | 2 | 260µs | # spent 247µs (217+31) within Petal::Tiny::BEGIN@4 which was called:
# once (217µs+31µs) by main::BEGIN@2 at line 4 # spent 247µs making 1 call to Petal::Tiny::BEGIN@4
# spent 12µs making 1 call to strict::import |
5 | 2 | 3.10ms | 2 | 3.61ms | # spent 3.54ms (3.25+292µs) within Petal::Tiny::BEGIN@5 which was called:
# once (3.25ms+292µs) by main::BEGIN@2 at line 5 # spent 3.54ms making 1 call to Petal::Tiny::BEGIN@5
# spent 75µs making 1 call to Exporter::import |
6 | |||||
7 | # REX/Perl 1.0 | ||||
8 | # Robert D. Cameron "REX: XML Shallow Parsing with Regular Expressions", | ||||
9 | # Technical Report TR 1998-17, School of Computing Science, Simon Fraser | ||||
10 | # University, November, 1998. | ||||
11 | # Copyright (c) 1998, Robert D. Cameron. | ||||
12 | # The following code may be freely used and distributed provided that | ||||
13 | # this copyright and citation notice remains intact and that modifications | ||||
14 | # or additions are clearly identified. | ||||
15 | 1 | 200ns | our $TextSE = "[^<]+"; | ||
16 | 1 | 100ns | our $UntilHyphen = "[^-]*-"; | ||
17 | 1 | 900ns | our $Until2Hyphens = "$UntilHyphen(?:[^-]$UntilHyphen)*-"; | ||
18 | 1 | 500ns | our $CommentCE = "$Until2Hyphens>?"; | ||
19 | 1 | 200ns | our $UntilRSBs = "[^\\]]*](?:[^\\]]+])*]+"; | ||
20 | 1 | 600ns | our $CDATA_CE = "$UntilRSBs(?:[^\\]>]$UntilRSBs)*>"; | ||
21 | 1 | 200ns | our $S = "[ \\n\\t\\r]+"; | ||
22 | 1 | 200ns | our $NameStrt = "[A-Za-z_:]|[^\\x00-\\x7F]"; | ||
23 | 1 | 200ns | our $NameChar = "[A-Za-z0-9_:.-]|[^\\x00-\\x7F]"; | ||
24 | 1 | 800ns | our $Name = "(?:$NameStrt)(?:$NameChar)*"; | ||
25 | 1 | 100ns | our $QuoteSE = "\"[^\"]*\"|'[^']*'"; | ||
26 | 1 | 2µs | our $DT_IdentSE = "$S$Name(?:$S(?:$Name|$QuoteSE))*"; | ||
27 | 1 | 500ns | our $MarkupDeclCE = "(?:[^\\]\"'><]+|$QuoteSE)*>"; | ||
28 | 1 | 100ns | our $S1 = "[\\n\\r\\t ]"; | ||
29 | 1 | 100ns | our $UntilQMs = "[^?]*\\?+"; | ||
30 | 1 | 700ns | our $PI_Tail = "\\?>|$S1$UntilQMs(?:[^>?]$UntilQMs)*>"; | ||
31 | 1 | 1µs | our $DT_ItemSE = "<(?:!(?:--$Until2Hyphens>|[^-]$MarkupDeclCE)|\\?$Name(?:$PI_Tail))|%$Name;|$S"; | ||
32 | 1 | 1µs | our $DocTypeCE = "$DT_IdentSE(?:$S)?(?:\\[(?:$DT_ItemSE)*](?:$S)?)?>?"; | ||
33 | 1 | 1µs | our $DeclCE = "--(?:$CommentCE)?|\\[CDATA\\[(?:$CDATA_CE)?|DOCTYPE(?:$DocTypeCE)?"; | ||
34 | 1 | 600ns | our $PI_CE = "$Name(?:$PI_Tail)?"; | ||
35 | 1 | 500ns | our $EndTagCE = "$Name(?:$S)?>?"; | ||
36 | 1 | 200ns | our $AttValSE = "\"[^<\"]*\"|'[^<']*'"; | ||
37 | 1 | 1µs | our $ElemTagCE = "$Name(?:$S$Name(?:$S)?=(?:$S)?(?:$AttValSE))*(?:$S)?/?>?"; | ||
38 | 1 | 1µs | our $ElemTagCE_Mod = "$S($Name)(?:$S)?=(?:$S)?($AttValSE)"; | ||
39 | 1 | 1µs | our $MarkupSPE = "<(?:!(?:$DeclCE)?|\\?(?:$PI_CE)?|/(?:$EndTagCE)?|(?:$ElemTagCE)?)"; | ||
40 | 1 | 3µs | our $XML_SPE = "$TextSE|$MarkupSPE"; | ||
41 | # REX END - thank you Robert for this 26 line XML parser - awesome ... | ||||
42 | |||||
43 | |||||
44 | 1 | 59µs | 2 | 49µs | our $RE_1 = qr /$ElemTagCE/; # spent 47µs making 1 call to Petal::Tiny::CORE:regcomp
# spent 2µs making 1 call to Petal::Tiny::CORE:qr |
45 | 1 | 29µs | 2 | 26µs | our $RE_2 = qr /$ElemTagCE_Mod/; # spent 25µs making 1 call to Petal::Tiny::CORE:regcomp
# spent 800ns making 1 call to Petal::Tiny::CORE:qr |
46 | 1 | 100ns | our $VARIABLE_RE_SIMPLE = qq |\$[A-Za-z_][A-Za-z0-9_\.:\/]+|; | ||
47 | 1 | 100ns | our $VARIABLE_RE_BRACKETS = qq |(?<!\$)\\{.*?(?<!\\\\)\\}|; | ||
48 | 1 | 700ns | our $STRING_TOKEN_RE = "($VARIABLE_RE_SIMPLE|$VARIABLE_RE_BRACKETS)"; | ||
49 | |||||
50 | 1 | 100ns | our $TAL = 'petal'; | ||
51 | |||||
52 | 1 | 300ns | our $STOP_RECURSE = 0; | ||
53 | |||||
54 | |||||
55 | # spent 625µs (473+152) within Petal::Tiny::new which was called 50 times, avg 13µs/call:
# 50 times (473µs+152µs) by main::RUNTIME at line 59 of opt.pl, avg 13µs/call | ||||
56 | 50 | 23µs | my $class = shift; | ||
57 | 50 | 28µs | $class = ref $class || $class; | ||
58 | 50 | 132µs | my $thing = shift; | ||
59 | 50 | 52µs | my $self = bless {}, $class; | ||
60 | 50 | 304µs | 50 | 152µs | if (defined $thing and $thing =~ /(\<|\n|\>)/) { $self->{xmldata} = $thing } # spent 152µs making 50 calls to Petal::Tiny::CORE:match, avg 3µs/call |
61 | elsif (defined $thing) { | ||||
62 | $self->{xmldata} = do { | ||||
63 | open my $xmldatafile, "<", $thing or die "cannot read open $thing"; | ||||
64 | my $xmldata = join '', <$xmldatafile>; | ||||
65 | close $xmldatafile; | ||||
66 | $xmldata; | ||||
67 | }; | ||||
68 | } | ||||
69 | 50 | 100µs | return $self; | ||
70 | } | ||||
71 | |||||
72 | |||||
73 | # spent 3.43s (463µs+3.43) within Petal::Tiny::process which was called 50 times, avg 68.5ms/call:
# 50 times (463µs+3.43s) by main::RUNTIME at line 60 of opt.pl, avg 68.5ms/call | ||||
74 | 50 | 14µs | my $self = shift; | ||
75 | 50 | 162µs | my $context = { @_ }; | ||
76 | 50 | 32µs | my $data = $self->{xmldata}; | ||
77 | 50 | 19µs | defined $data or return; # empty data, empty result. | ||
78 | 50 | 221µs | 50 | 3.43s | return $self->makeitso($data, $context); # earl grey. hot. # spent 3.43s making 50 calls to Petal::Tiny::makeitso, avg 68.5ms/call |
79 | } | ||||
80 | |||||
81 | |||||
82 | # spent 3.43s (553ms+2.87) within Petal::Tiny::makeitso which was called 4170 times, avg 821µs/call:
# 2880 times (293ms+-293ms) by Petal::Tiny::makeitso at line 119, avg 0s/call
# 990 times (110ms+-110ms) by Petal::Tiny::makeitso_block at line 176, avg 0s/call
# 250 times (59.5ms+-59.5ms) by Petal::Tiny::tal_omit_tag at line 335, avg 0s/call
# 50 times (90.6ms+3.33s) by Petal::Tiny::process at line 78, avg 68.5ms/call | ||||
83 | 4170 | 766µs | my $self = shift; | ||
84 | 4170 | 605µs | my $xml = shift; | ||
85 | 4170 | 35.1ms | 100 | 15.4ms | my @xml = ref $xml ? @{$xml} : ( $xml =~ /$XML_SPE/g ); # spent 15.2ms making 50 calls to Petal::Tiny::CORE:match, avg 303µs/call
# spent 233µs making 50 calls to Petal::Tiny::CORE:regcomp, avg 5µs/call |
86 | 4170 | 1.01ms | my $context = shift || {}; | ||
87 | 4170 | 1.03ms | my @head = (); | ||
88 | 4170 | 972µs | my @body = (); | ||
89 | 4170 | 883µs | my @tail = (); | ||
90 | 4170 | 1.14ms | while (@xml) { | ||
91 | 6940 | 1.76ms | my $elem = shift @xml; | ||
92 | 6940 | 4.96ms | 6940 | 116ms | tag_self_close ($elem) and do { # spent 116ms making 6940 calls to Petal::Tiny::tag_self_close, avg 17µs/call |
93 | 760 | 248µs | push @body, $elem; | ||
94 | 760 | 2.62ms | @tail = @xml; | ||
95 | 760 | 864µs | last; | ||
96 | }; | ||||
97 | 6180 | 4.17ms | 6180 | 161ms | my $opentag = tag_open ($elem); # spent 161ms making 6180 calls to Petal::Tiny::tag_open, avg 26µs/call |
98 | 6180 | 1.06ms | $opentag and do { | ||
99 | 2310 | 689µs | push @body, $elem; | ||
100 | 2310 | 553µs | my $balance = 1; | ||
101 | 2310 | 755µs | while ($balance) { | ||
102 | 78680 | 11.3ms | @xml or confess "cannot find closing tag for $elem"; | ||
103 | 78680 | 15.5ms | my $elem = shift @xml; | ||
104 | 78680 | 49.0ms | 78680 | 1.29s | tag_open ($elem) and $balance++; # spent 1.29s making 78680 calls to Petal::Tiny::tag_open, avg 16µs/call |
105 | 78680 | 50.9ms | 78680 | 520ms | tag_close ($elem) and $balance--; # spent 520ms making 78680 calls to Petal::Tiny::tag_close, avg 7µs/call |
106 | 78680 | 29.8ms | push @body, $elem; | ||
107 | } | ||||
108 | 2310 | 9.06ms | @tail = @xml; | ||
109 | 2310 | 2.30ms | last; | ||
110 | }; | ||||
111 | 3870 | 2.59ms | 3870 | 27.9ms | tag_close ($elem) and confess "cannot find opening tag for $elem"; # spent 27.9ms making 3870 calls to Petal::Tiny::tag_close, avg 7µs/call |
112 | |||||
113 | 3870 | 4.08ms | 3870 | 22.2ms | $elem = $self->_interpolate_dollar($context, $elem, 'resolve_expression'); # spent 22.2ms making 3870 calls to Petal::Tiny::_interpolate_dollar, avg 6µs/call |
114 | 3870 | 2.64ms | push @head, $elem; | ||
115 | } | ||||
116 | 4170 | 1.10ms | my @res = (); | ||
117 | 4170 | 1.61ms | push @res, @head if (@head); | ||
118 | 4170 | 9.29ms | 3070 | 2.97s | push @res, $self->makeitso_block(\@body, $context) if (@body); # spent 15.5s making 3070 calls to Petal::Tiny::makeitso_block, avg 5.04ms/call, recursion: max depth 11, sum of overlapping time 12.5s |
119 | 4170 | 4.29ms | 2880 | 0s | push @res, $self->makeitso(\@tail, $context) if (@tail); # spent 24.0s making 2880 calls to Petal::Tiny::makeitso, avg 8.35ms/call, recursion: max depth 48, sum of overlapping time 24.0s |
120 | 4170 | 25.3ms | return join '', @res; | ||
121 | } | ||||
122 | |||||
123 | |||||
124 | # spent 22.2ms (20.6+1.60) within Petal::Tiny::_interpolate_dollar which was called 3870 times, avg 6µs/call:
# 3870 times (20.6ms+1.60ms) by Petal::Tiny::makeitso at line 113, avg 6µs/call | ||||
125 | 3870 | 1.75ms | my ($self, $context, $string, $method) = @_; | ||
126 | |||||
127 | # spent 738µs (80+658) within Petal::Tiny::__ANON__[/home/lbr/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/Petal/Tiny.pm:133] which was called 10 times, avg 74µs/call:
# 10 times (80µs+658µs) by Petal::Tiny::_interpolate_dollar at line 136, avg 74µs/call | ||||
128 | 10 | 36µs | my $what = shift; | ||
129 | 10 | 20µs | 10 | 658µs | my $res = $self->$method($what, $context); # spent 658µs making 10 calls to Petal::Tiny::resolve_expression, avg 66µs/call |
130 | 10 | 22µs | return $res if defined $res; | ||
131 | carp "'$what' in \$-interpolation resolved to undef"; | ||||
132 | return ""; | ||||
133 | 3870 | 6.26ms | }; | ||
134 | |||||
135 | 3870 | 5.12ms | 3870 | 795µs | if ($string =~ /\$/) { # spent 795µs making 3870 calls to Petal::Tiny::CORE:match, avg 205ns/call |
136 | 20 | 121µs | 40 | 795µs | $string =~ s/(?<!\$) \$\{ ( [^{}]+ ) \} / $subst->($1) /xegi; # spent 738µs making 10 calls to Petal::Tiny::__ANON__[Petal/Tiny.pm:133], avg 74µs/call
# spent 39µs making 10 calls to Petal::Tiny::CORE:subst, avg 4µs/call
# spent 18µs making 20 calls to Petal::Tiny::CORE:substcont, avg 925ns/call |
137 | 10 | 17µs | 10 | 3µs | $string =~ s/(?<!\$) \$\{? ( [a-z0-9-\/\:\_]+ ) \}? / $subst->($1) /xegi; # spent 3µs making 10 calls to Petal::Tiny::CORE:subst, avg 330ns/call |
138 | 10 | 17µs | 10 | 2µs | $string =~ s/\$\$/\$/g; # spent 2µs making 10 calls to Petal::Tiny::CORE:subst, avg 180ns/call |
139 | } | ||||
140 | 3870 | 10.4ms | return $string; | ||
141 | } | ||||
142 | |||||
143 | |||||
144 | # spent 43.4ms (41.8+1.54) within Petal::Tiny::namespace which was called 3070 times, avg 14µs/call:
# 3070 times (41.8ms+1.54ms) by Petal::Tiny::makeitso_block at line 168, avg 14µs/call | ||||
145 | 3070 | 562µs | my $self = shift; | ||
146 | 3070 | 435µs | my $node = shift; | ||
147 | 3070 | 6.88ms | for my $k (keys %{$node}) { | ||
148 | 14440 | 32.9ms | 14440 | 1.49ms | $k =~ /^xmlns\:/ or next; # spent 1.49ms making 14440 calls to Petal::Tiny::CORE:match, avg 103ns/call |
149 | 50 | 49µs | my $v = $node->{$k}; | ||
150 | 50 | 58µs | if ($v eq 'http://purl.org/petal/1.0/') { | ||
151 | 50 | 62µs | delete $node->{$k}; | ||
152 | 50 | 126µs | 50 | 56µs | $k =~ s/^xmlns\://; # spent 56µs making 50 calls to Petal::Tiny::CORE:subst, avg 1µs/call |
153 | 50 | 123µs | return $k; | ||
154 | } | ||||
155 | } | ||||
156 | 3020 | 8.45ms | return; | ||
157 | } | ||||
158 | |||||
159 | |||||
160 | # spent 2.97s (77.3ms+2.90) within Petal::Tiny::makeitso_block which was called 3070 times, avg 968µs/call:
# 3070 times (77.3ms+2.90s) by Petal::Tiny::makeitso at line 118, avg 968µs/call | ||||
161 | 3070 | 604µs | my $self = shift; | ||
162 | 3070 | 522µs | my $xml = shift; | ||
163 | 3070 | 420µs | my $context = shift; | ||
164 | 3070 | 10.0ms | my @xml = ref $xml ? @{$xml} : ( $xml =~ /$XML_SPE/g ); | ||
165 | 3070 | 992µs | my $tag = shift (@xml); | ||
166 | 3070 | 889µs | my $gat = pop (@xml); | ||
167 | 3070 | 3.01ms | 3830 | 166ms | my $node = tag_open ($tag) || tag_self_close ($tag); # spent 130ms making 3070 calls to Petal::Tiny::tag_open, avg 42µs/call
# spent 35.5ms making 760 calls to Petal::Tiny::tag_self_close, avg 47µs/call |
168 | 3070 | 3.05ms | 3070 | 43.4ms | my $ns = $self->namespace($node); # spent 43.4ms making 3070 calls to Petal::Tiny::namespace, avg 14µs/call |
169 | 3070 | 1.28ms | local $TAL = $ns || $TAL; | ||
170 | 3070 | 3.00ms | 3070 | 54.9ms | if (has_instructions ($node)) { # spent 54.9ms making 3070 calls to Petal::Tiny::has_instructions, avg 18µs/call |
171 | 1680 | 7.50ms | $context = { %{$context} }; | ||
172 | 1680 | 7.99ms | 1680 | 1.65s | return $self->tal_on_error($node, \@xml, $gat, $context); # spent 4.79s making 1680 calls to Petal::Tiny::tal_on_error, avg 2.85ms/call, recursion: max depth 4, sum of overlapping time 3.14s |
173 | } | ||||
174 | else { | ||||
175 | 1390 | 319µs | 50 | 816µs | $tag = node2tag ($node) if ($ns); # spent 816µs making 50 calls to Petal::Tiny::node2tag, avg 16µs/call |
176 | 1390 | 4.75ms | 990 | 0s | if ($gat) { return $tag . $self->makeitso(\@xml, $context) . $gat } # spent 10.3s making 990 calls to Petal::Tiny::makeitso, avg 10.4ms/call, recursion: max depth 35, sum of overlapping time 10.3s |
177 | 400 | 970µs | else { return $tag } # self-closing tag | ||
178 | } | ||||
179 | } | ||||
180 | |||||
181 | |||||
182 | # spent 1.65s (6.90ms+1.64) within Petal::Tiny::tal_on_error which was called 1680 times, avg 980µs/call:
# 1680 times (6.90ms+1.64s) by Petal::Tiny::makeitso_block at line 172, avg 980µs/call | ||||
183 | 1680 | 925µs | my ($self, $node, $xml, $end, $context) = @_; | ||
184 | 1680 | 1.96ms | my $stuff = delete $node->{"$TAL:on-error"}; | ||
185 | 1680 | 14.4ms | 1680 | 1.64s | defined $stuff or return $self->tal_define($node, $xml, $end, $context); # spent 4.78s making 1680 calls to Petal::Tiny::tal_define, avg 2.85ms/call, recursion: max depth 4, sum of overlapping time 3.14s |
186 | my $nodeCopy = { %{$node} }; | ||||
187 | my $res = eval { $self->tal_define($node, $xml, $end, $context) }; | ||||
188 | if ($@) { | ||||
189 | my @result = (); | ||||
190 | for my $k (keys %{$nodeCopy}) { delete $nodeCopy->{$k} if $k =~ /^$TAL:/ } | ||||
191 | delete $nodeCopy->{_close} and $end = "</$nodeCopy->{_tag}>"; # deal with self closing tags | ||||
192 | push @result, node2tag ($nodeCopy); | ||||
193 | push @result, $self->resolve_expression($stuff, $context); | ||||
194 | push @result, $end; | ||||
195 | return join '', @result; | ||||
196 | } | ||||
197 | else { | ||||
198 | return $res; | ||||
199 | } | ||||
200 | } | ||||
201 | |||||
202 | |||||
203 | # spent 1.64s (10.3ms+1.63) within Petal::Tiny::tal_define which was called 1680 times, avg 979µs/call:
# 1680 times (10.3ms+1.63s) by Petal::Tiny::tal_on_error at line 185, avg 979µs/call | ||||
204 | 1680 | 611µs | my ($self, $node, $xml, $end, $context) = @_; | ||
205 | 1680 | 1.21ms | my $stuff = delete $node->{"$TAL:define"}; | ||
206 | 1680 | 8.26ms | 1680 | 1.64s | defined $stuff || return $self->tal_condition($node, $xml, $end, $context); # spent 4.77s making 1680 calls to Petal::Tiny::tal_condition, avg 2.84ms/call, recursion: max depth 4, sum of overlapping time 3.13s |
207 | my $newContext = { %{$context} }; | ||||
208 | my $define = trim ($stuff); | ||||
209 | for my $def (split /;(?!;)/, $define) { | ||||
210 | $def = trim($def); | ||||
211 | my ($symbol, $expression) = split /\s+/, $def, 2; | ||||
212 | $newContext->{$symbol} = $self->resolve_expression($expression, $newContext); | ||||
213 | } | ||||
214 | return $self->tal_condition($node, $xml, $end, $newContext); | ||||
215 | } | ||||
216 | |||||
217 | |||||
218 | # spent 1.64s (16.4ms+1.63) within Petal::Tiny::tal_condition which was called 1680 times, avg 978µs/call:
# 1680 times (16.4ms+1.63s) by Petal::Tiny::tal_define at line 206, avg 978µs/call | ||||
219 | 1680 | 531µs | my ($self, $node, $xml, $end, $context) = @_; | ||
220 | 1680 | 1.42ms | my $stuff = delete $node->{"$TAL:condition"}; | ||
221 | 1680 | 3.13ms | 1470 | 36.0ms | defined $stuff or return $self->tal_repeat($node, $xml, $end, $context); # spent 3.15s making 1470 calls to Petal::Tiny::tal_repeat, avg 2.14ms/call, recursion: max depth 4, sum of overlapping time 3.12s |
222 | |||||
223 | 210 | 223µs | 210 | 5.00ms | my $condition = trim ($stuff); # spent 5.00ms making 210 calls to Petal::Tiny::trim, avg 24µs/call |
224 | 210 | 292µs | for my $cond (split /;(?!;)/, $condition) { | ||
225 | 210 | 185µs | 210 | 1.15ms | $cond = trim($cond); # spent 1.15ms making 210 calls to Petal::Tiny::trim, avg 5µs/call |
226 | 210 | 531µs | 210 | 27.8ms | $self->resolve_expression($cond, $context) or return ''; # spent 27.8ms making 210 calls to Petal::Tiny::resolve_expression, avg 132µs/call |
227 | } | ||||
228 | 80 | 198µs | 80 | 1.57s | return $self->tal_repeat($node, $xml, $end, $context); # spent 1.57s making 80 calls to Petal::Tiny::tal_repeat, avg 19.6ms/call |
229 | } | ||||
230 | |||||
231 | |||||
232 | sub tal_repeat { | ||||
233 | 1550 | 454µs | my ($self, $node, $xml, $end, $context) = @_; | ||
234 | 1550 | 1.02ms | my $stuff = delete $node->{"$TAL:repeat"}; | ||
235 | 1550 | 12.9ms | 1540 | 1.60s | defined $stuff or return $self->tal_content($node, $xml, $end, $context); # spent 4.71s making 1540 calls to Petal::Tiny::tal_content, avg 3.06ms/call, recursion: max depth 4, sum of overlapping time 3.11s |
236 | |||||
237 | 10 | 21µs | my @loops = split /;/, $stuff; | ||
238 | 10 | 4µs | my $count = 0; | ||
239 | 10 | 68µs | 10 | 1.96ms | return $self->_do_repeat(\$count, 1, \@loops, $node, $xml, $end, { %$context }); # spent 1.96ms making 10 calls to Petal::Tiny::_do_repeat, avg 196µs/call |
240 | } | ||||
241 | |||||
242 | # spent 1.96ms (303µs+1.66) within Petal::Tiny::_do_repeat which was called 10 times, avg 196µs/call:
# 10 times (303µs+1.66ms) by Petal::Tiny::tal_repeat at line 239, avg 196µs/call | ||||
243 | 10 | 8µs | my ($self, $count, $last, $loops_ref, $node, $xml, $end, $context) = @_; | ||
244 | |||||
245 | 10 | 8µs | my @loops = @$loops_ref; | ||
246 | 10 | 5µs | my $stuff = shift @loops; | ||
247 | 10 | 14µs | 10 | 87µs | my $repeat = trim ($stuff); # spent 87µs making 10 calls to Petal::Tiny::trim, avg 9µs/call |
248 | 10 | 16µs | my ($symbol, $expression) = split /\s+/, $repeat, 2; | ||
249 | 10 | 16µs | 10 | 485µs | my $array = $self->resolve_expression($expression, $context); # spent 485µs making 10 calls to Petal::Tiny::resolve_expression, avg 48µs/call |
250 | 10 | 10µs | $array = [ $array ] unless ref $array; # we don't judge | ||
251 | 10 | 3µs | my @result; | ||
252 | 10 | 22µs | foreach my $idx (0 .. $#$array) { | ||
253 | 10 | 6µs | my $item = $array->[$idx]; | ||
254 | 10 | 10µs | $context->{$symbol} = $item; | ||
255 | 10 | 20µs | if (@loops) { | ||
256 | push @result, $self->_do_repeat($count, $last && $idx == $#$array, \@loops, $node, $xml, $end, $context); | ||||
257 | } | ||||
258 | else { | ||||
259 | 10 | 5µs | $$count++; | ||
260 | 10 | 10µs | $context->{repeat} = {}; | ||
261 | 10 | 9µs | $context->{repeat}->{index} = $$count; | ||
262 | 10 | 7µs | $context->{repeat}->{number} = $$count; | ||
263 | 10 | 13µs | $context->{repeat}->{even} = $$count%2 ? 0 : 1; | ||
264 | 10 | 7µs | $context->{repeat}->{odd} = $$count%2 ? 1 : 0; | ||
265 | 10 | 7µs | $context->{repeat}->{start} = $$count == 1 ? 1 : 0; | ||
266 | 10 | 9µs | $context->{repeat}->{end} = $last && $idx == $#$array ? 1 : 0; | ||
267 | 10 | 13µs | $context->{repeat}->{inner} = $context->{repeat}->{start} || $context->{repeat}->{end} ? 0 : 1; | ||
268 | 10 | 40µs | 10 | 1.09ms | push @result, $self->tal_content({ %$node }, $xml, $end, $context); # spent 1.09ms making 10 calls to Petal::Tiny::tal_content, avg 109µs/call |
269 | } | ||||
270 | } | ||||
271 | 10 | 30µs | return join '', @result; | ||
272 | } | ||||
273 | |||||
274 | |||||
275 | sub tal_content { | ||||
276 | 1550 | 470µs | my ($self, $node, $xml, $end, $context) = @_; | ||
277 | 1550 | 1.52ms | my $stuff = delete $node->{"$TAL:content"}; | ||
278 | 1550 | 1.56ms | 620 | 1.57s | defined $stuff or return $self->tal_replace($node, $xml, $end, $context); # spent 4.54s making 620 calls to Petal::Tiny::tal_replace, avg 7.33ms/call, recursion: max depth 4, sum of overlapping time 2.97s |
279 | |||||
280 | 930 | 982µs | 930 | 79.6ms | my $res = $self->resolve_expression($stuff, $context); # spent 79.6ms making 930 calls to Petal::Tiny::resolve_expression, avg 86µs/call |
281 | 930 | 829µs | $xml = defined $res ? [ $res ] : []; | ||
282 | 930 | 626µs | delete $node->{_close} and $end = "</$node->{_tag}>"; # deal with self closing tags | ||
283 | |||||
284 | # set the stop recurse flag so that if content contains $foo and $bar, | ||||
285 | # those aren't interpolated as variables. | ||||
286 | 930 | 430µs | local ( $STOP_RECURSE ) = ( 1 ); | ||
287 | 930 | 2.59ms | 930 | 5.62ms | return $self->tal_replace($node, $xml, $end, $context); # spent 76.4ms making 930 calls to Petal::Tiny::tal_replace, avg 82µs/call, recursion: max depth 4, sum of overlapping time 70.8ms |
288 | } | ||||
289 | |||||
290 | |||||
291 | sub tal_replace { | ||||
292 | 1550 | 552µs | my ($self, $node, $xml, $end, $context) = @_; | ||
293 | 1550 | 1.10ms | my $stuff = delete $node->{"$TAL:replace"}; | ||
294 | 1550 | 8.94ms | 1500 | 1.58s | defined $stuff or return $self->tal_attributes($node, $xml, $end, $context); # spent 4.61s making 1500 calls to Petal::Tiny::tal_attributes, avg 3.07ms/call, recursion: max depth 4, sum of overlapping time 3.03s |
295 | 50 | 62µs | 50 | 4.19ms | my $res = $self->resolve_expression($stuff, $context); # spent 4.19ms making 50 calls to Petal::Tiny::resolve_expression, avg 84µs/call |
296 | 50 | 106µs | return defined $res ? $res : ''; | ||
297 | } | ||||
298 | |||||
299 | |||||
300 | # spent 1.58s (19.5ms+1.56) within Petal::Tiny::tal_attributes which was called 1500 times, avg 1.05ms/call:
# 1500 times (19.5ms+1.56s) by Petal::Tiny::tal_replace at line 294, avg 1.05ms/call | ||||
301 | 1500 | 511µs | my ($self, $node, $xml, $end, $context) = @_; | ||
302 | 1500 | 1.41ms | my $stuff = delete $node->{"$TAL:attributes"}; | ||
303 | 1500 | 1.88ms | 720 | 1.56s | defined $stuff or return $self->tal_omit_tag($node, $xml, $end, $context); # spent 1.57s making 720 calls to Petal::Tiny::tal_omit_tag, avg 2.18ms/call, recursion: max depth 4, sum of overlapping time 8.24ms |
304 | |||||
305 | 780 | 747µs | 780 | 16.8ms | my $attributes = trim ($stuff); # spent 16.8ms making 780 calls to Petal::Tiny::trim, avg 21µs/call |
306 | 780 | 1.55ms | for my $att (split /;(?!;)/, $attributes) { | ||
307 | 980 | 904µs | 980 | 13.0ms | $att = trim ($att); # spent 13.0ms making 980 calls to Petal::Tiny::trim, avg 13µs/call |
308 | 980 | 1.16ms | my ($symbol, $expression) = split /\s+/, $att, 2; | ||
309 | 980 | 5.60ms | 980 | 720µs | my $add = ($symbol =~ s/^\+//); # spent 720µs making 980 calls to Petal::Tiny::CORE:subst, avg 734ns/call |
310 | 980 | 1000µs | 980 | 117ms | my $new = $self->resolve_expression($expression, $context); # spent 117ms making 980 calls to Petal::Tiny::resolve_expression, avg 120µs/call |
311 | 980 | 1.04ms | if (defined $new) { | ||
312 | 380 | 87µs | if ($add) { | ||
313 | 70 | 39µs | my $old = $node->{$symbol}; | ||
314 | 70 | 36µs | $old = "" unless defined $old; | ||
315 | 70 | 46µs | $new = $old . $new; | ||
316 | } | ||||
317 | 380 | 338µs | $node->{$symbol} = $new; | ||
318 | } | ||||
319 | else { | ||||
320 | 600 | 197µs | delete $node->{$symbol} unless $add; | ||
321 | } | ||||
322 | } | ||||
323 | 780 | 1.98ms | 780 | 3.58ms | return $self->tal_omit_tag($node, $xml, $end, $context); # spent 2.87s making 780 calls to Petal::Tiny::tal_omit_tag, avg 3.68ms/call, recursion: max depth 4, sum of overlapping time 2.87s |
324 | } | ||||
325 | |||||
326 | |||||
327 | sub tal_omit_tag { | ||||
328 | 1500 | 565µs | my ($self, $node, $xml, $end, $context) = @_; | ||
329 | 1500 | 1.19ms | my $stuff = delete $node->{"$TAL:omit-tag"}; | ||
330 | 1500 | 468µs | my $omit = defined $stuff ? do { $stuff eq '' ? 1 : $self->resolve_expression($stuff, $context) } : undef; | ||
331 | 1500 | 287µs | $omit and not $end and return ''; # omit-tag on a self-closing tag means *poof*, nothing left | ||
332 | 1500 | 465µs | my @result = (); | ||
333 | 1500 | 1.65ms | 1470 | 24.7ms | push @result, node2tag ($node) unless ($omit); # spent 24.7ms making 1470 calls to Petal::Tiny::node2tag, avg 17µs/call |
334 | 1500 | 455µs | if ($end) { | ||
335 | 1180 | 1.16ms | 250 | 0s | push @result, do { $STOP_RECURSE ? join '', @{$xml} : $self->makeitso($xml, $context) }; # spent 4.41s making 250 calls to Petal::Tiny::makeitso, avg 17.6ms/call, recursion: max depth 45, sum of overlapping time 4.41s |
336 | 1180 | 489µs | push @result, $end unless ($omit); | ||
337 | } | ||||
338 | 1500 | 3.60ms | return join '', @result; | ||
339 | } | ||||
340 | |||||
341 | |||||
342 | # spent 230ms (25.7+204) within Petal::Tiny::resolve_expression which was called 2190 times, avg 105µs/call:
# 980 times (9.51ms+108ms) by Petal::Tiny::tal_attributes at line 310, avg 120µs/call
# 930 times (9.62ms+69.9ms) by Petal::Tiny::tal_content at line 280, avg 86µs/call
# 210 times (5.72ms+22.1ms) by Petal::Tiny::tal_condition at line 226, avg 132µs/call
# 50 times (561µs+3.63ms) by Petal::Tiny::tal_replace at line 295, avg 84µs/call
# 10 times (116µs+543µs) by Petal::Tiny::__ANON__[/home/lbr/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/Petal/Tiny.pm:133] at line 129, avg 66µs/call
# 10 times (122µs+363µs) by Petal::Tiny::_do_repeat at line 249, avg 48µs/call | ||||
343 | 2190 | 424µs | my $self = shift; | ||
344 | 2190 | 1.88ms | 2190 | 29.3ms | my $expr = trim(shift); # spent 29.3ms making 2190 calls to Petal::Tiny::trim, avg 13µs/call |
345 | 2190 | 592µs | my $context = shift || confess "resolve_expression() : no context"; | ||
346 | 2190 | 2.94ms | 2190 | 772µs | $expr =~ s/\;\;/;/g; # spent 772µs making 2190 calls to Petal::Tiny::CORE:subst, avg 352ns/call |
347 | 2190 | 2.67ms | 2190 | 584µs | $expr =~ s/\$\$/\$/g; # spent 584µs making 2190 calls to Petal::Tiny::CORE:subst, avg 267ns/call |
348 | 2190 | 668µs | $expr eq 'nothing' and return undef; | ||
349 | 2190 | 2.85ms | 2190 | 498µs | $expr =~ s/^fresh\s+//; # spent 498µs making 2190 calls to Petal::Tiny::CORE:subst, avg 228ns/call |
350 | 2190 | 3.09ms | 2190 | 576µs | my $structure = ($expr =~ s/^structure\s+//); # spent 576µs making 2190 calls to Petal::Tiny::CORE:subst, avg 263ns/call |
351 | 2190 | 2.25ms | 2190 | 163ms | my $resolved = $self->resolve($expr, $context); # spent 163ms making 2190 calls to Petal::Tiny::resolve, avg 74µs/call |
352 | 2190 | 5.03ms | 2150 | 9.60ms | return $structure ? $resolved : xmlencode($resolved); # spent 9.60ms making 2150 calls to Petal::Tiny::xmlencode, avg 4µs/call |
353 | } | ||||
354 | |||||
355 | # spent 6.65ms within Petal::Tiny::reftype which was called 8250 times, avg 805ns/call:
# 4120 times (3.79ms+0s) by Petal::Tiny::resolve at line 387, avg 921ns/call
# 4120 times (2.84ms+0s) by Petal::Tiny::resolve at line 407, avg 690ns/call
# 10 times (6µs+0s) by Petal::Tiny::modifier_true at line 441, avg 650ns/call | ||||
356 | 8250 | 1.67ms | my ($self, $obj) = @_; | ||
357 | 8250 | 16.8ms | return ref $obj; | ||
358 | } | ||||
359 | |||||
360 | # spent 163ms (107+56.2) within Petal::Tiny::resolve which was called 4950 times, avg 33µs/call:
# 2550 times (26.9ms+-26.9ms) by Petal::Tiny::resolve at line 381, avg 0s/call
# 2190 times (71.0ms+91.9ms) by Petal::Tiny::resolve_expression at line 351, avg 74µs/call
# 210 times (8.81ms+-8.81ms) by Petal::Tiny::modifier_true at line 440, avg 0s/call | ||||
361 | 4950 | 776µs | my $self = shift; | ||
362 | 4950 | 3.33ms | 4950 | 40.2ms | my $expr = trim(shift); # spent 40.2ms making 4950 calls to Petal::Tiny::trim, avg 8µs/call |
363 | 4950 | 975µs | my $context = shift || confess "resolve() : no context"; | ||
364 | 4950 | 11.4ms | 4950 | 1.20ms | $expr =~ /:(?!pattern)/ and do { # spent 1.20ms making 4950 calls to Petal::Tiny::CORE:match, avg 243ns/call |
365 | 210 | 354µs | my ($mod, $expr) = split /:(?!pattern)/, $expr, 2; | ||
366 | 210 | 145µs | my $meth = "modifier_$mod"; | ||
367 | 210 | 1.39ms | 420 | 11.9ms | $self->can("modifier_$mod") and return $self->$meth($expr, $context); # spent 9.02ms making 130 calls to Petal::Tiny::modifier_true, avg 69µs/call
# spent 2.50ms making 80 calls to Petal::Tiny::modifier_false, avg 31µs/call
# spent 371µs making 210 calls to UNIVERSAL::can, avg 2µs/call |
368 | confess "unknown modifier $mod"; | ||||
369 | }; | ||||
370 | 4740 | 6.12ms | 4740 | 1.46ms | $expr =~ /^--/ and do { # spent 1.46ms making 4740 calls to Petal::Tiny::CORE:match, avg 308ns/call |
371 | 2530 | 12.5ms | 2530 | 2.44ms | $expr =~ s/^--//; # spent 2.44ms making 2530 calls to Petal::Tiny::CORE:subst, avg 966ns/call |
372 | 2530 | 11.9ms | return $expr; | ||
373 | }; | ||||
374 | 2210 | 7.93ms | 2210 | 588µs | $expr =~ s/\r/ /g; # spent 588µs making 2210 calls to Petal::Tiny::CORE:subst, avg 266ns/call |
375 | 2210 | 3.39ms | my ($what, @args) = split /\s+/, $expr; | ||
376 | 2210 | 362µs | defined $what or return; | ||
377 | |||||
378 | 2210 | 2.42ms | my (@path) = split /\//, $what; | ||
379 | 2210 | 565µs | my @resolved = (); | ||
380 | 2210 | 520µs | my $obj = $context; | ||
381 | 4760 | 5.62ms | 2550 | 0s | @args = map { $self->resolve($_, $context) } @args; # spent 53.8ms making 2550 calls to Petal::Tiny::resolve, avg 21µs/call, recursion: max depth 1, sum of overlapping time 53.8ms |
382 | 2210 | 945µs | while (@path) { | ||
383 | 4120 | 1.03ms | my $attribute_or_method = shift @path; | ||
384 | 4120 | 1.17ms | push @resolved, $attribute_or_method; | ||
385 | 4120 | 1.99ms | my $resolved = join '/', @resolved; | ||
386 | 4120 | 698µs | $obj or confess "cannot fetch $what, because $resolved is undefined"; | ||
387 | 4120 | 3.25ms | 4120 | 3.79ms | my $reftype = $self->reftype($obj); # spent 3.79ms making 4120 calls to Petal::Tiny::reftype, avg 921ns/call |
388 | 4120 | 564µs | $reftype or confess "cannot fetch $what, because $resolved is not a reference"; | ||
389 | |||||
390 | 4120 | 3.37ms | if ($reftype eq 'ARRAY') { | ||
391 | $obj = $obj->[$attribute_or_method]; | ||||
392 | } | ||||
393 | elsif ($reftype eq 'HASH') { | ||||
394 | $obj = $obj->{$attribute_or_method}; | ||||
395 | } | ||||
396 | elsif ($obj->can($attribute_or_method)) { | ||||
397 | if (@path) { | ||||
398 | $obj = $obj->$attribute_or_method(); | ||||
399 | } | ||||
400 | else { | ||||
401 | $obj = $obj->$attribute_or_method(@args); | ||||
402 | @args = (); | ||||
403 | } | ||||
404 | } | ||||
405 | |||||
406 | # now, check if what we found was a code-ref | ||||
407 | 4120 | 2.68ms | 4120 | 2.84ms | $reftype = $self->reftype($obj); # spent 2.84ms making 4120 calls to Petal::Tiny::reftype, avg 690ns/call |
408 | 4120 | 1.24ms | if ($reftype eq 'CODE') { | ||
409 | 1880 | 676µs | if (@path) { | ||
410 | $obj = $obj->(); | ||||
411 | } | ||||
412 | else { | ||||
413 | 1880 | 2.39ms | 1880 | 2.34ms | $obj = $obj->(@args); # spent 914µs making 570 calls to main::__ANON__[opt.pl:19], avg 2µs/call
# spent 410µs making 450 calls to main::__ANON__[opt.pl:17], avg 911ns/call
# spent 395µs making 370 calls to main::__ANON__[opt.pl:18], avg 1µs/call
# spent 215µs making 180 calls to main::__ANON__[opt.pl:16], avg 1µs/call
# spent 87µs making 60 calls to main::__ANON__[opt.pl:13], avg 1µs/call
# spent 76µs making 80 calls to main::__ANON__[opt.pl:14], avg 952ns/call
# spent 74µs making 50 calls to main::__ANON__[opt.pl:12], avg 1µs/call
# spent 52µs making 40 calls to main::__ANON__[opt.pl:15], avg 1µs/call
# spent 44µs making 30 calls to main::__ANON__[opt.pl:11], avg 1µs/call
# spent 28µs making 20 calls to main::__ANON__[opt.pl:10], avg 1µs/call
# spent 17µs making 10 calls to main::__ANON__[opt.pl:8], avg 2µs/call
# spent 17µs making 10 calls to main::__ANON__[opt.pl:9], avg 2µs/call
# spent 15µs making 10 calls to main::__ANON__[opt.pl:25], avg 1µs/call |
414 | 1880 | 912µs | @args = (); | ||
415 | } | ||||
416 | } | ||||
417 | |||||
418 | # if we're done with @path and there's a single arg, use it to look up in array/hash | ||||
419 | 4120 | 1.49ms | if (not @path and @args == 1) { | ||
420 | $reftype = $self->reftype($obj); | ||||
421 | |||||
422 | if ($reftype eq 'ARRAY') { | ||||
423 | $obj = $obj->[ $args[0] ]; | ||||
424 | last; | ||||
425 | } | ||||
426 | elsif ($reftype eq 'HASH') { | ||||
427 | $obj = $obj->{ $args[0] }; | ||||
428 | last; | ||||
429 | } | ||||
430 | } | ||||
431 | |||||
432 | 4120 | 2.55ms | not @path and @args and confess "cannot resolve expression $expr"; | ||
433 | } | ||||
434 | 2210 | 3.86ms | return $obj; | ||
435 | } | ||||
436 | |||||
437 | |||||
438 | sub modifier_true { | ||||
439 | 210 | 46µs | my $self = shift; | ||
440 | 210 | 225µs | 210 | 0s | my $arg = $self->resolve(shift(), shift()); # spent 10.5ms making 210 calls to Petal::Tiny::resolve, avg 50µs/call, recursion: max depth 1, sum of overlapping time 10.5ms |
441 | 210 | 74µs | 10 | 6µs | ref $arg and $self->reftype($arg) eq 'ARRAY' and return @{$arg}; # spent 6µs making 10 calls to Petal::Tiny::reftype, avg 650ns/call |
442 | 200 | 319µs | return $arg ? 1 : 0; | ||
443 | } | ||||
444 | |||||
445 | |||||
446 | # spent 2.50ms (285µs+2.22) within Petal::Tiny::modifier_false which was called 80 times, avg 31µs/call:
# 80 times (285µs+2.22ms) by Petal::Tiny::resolve at line 367, avg 31µs/call | ||||
447 | 80 | 24µs | my $self = shift; | ||
448 | 80 | 250µs | 80 | 2.22ms | return not $self->modifier_true(@_); # spent 2.22ms making 80 calls to Petal::Tiny::modifier_true, avg 28µs/call |
449 | } | ||||
450 | |||||
451 | |||||
452 | sub modifier_string { | ||||
453 | my $self = shift; | ||||
454 | my $string = shift; | ||||
455 | my $context = shift; | ||||
456 | $string = $self->_interpolate_dollar($context, $string, 'resolve'); | ||||
457 | return $string; | ||||
458 | } | ||||
459 | |||||
460 | |||||
461 | sub node2tag { | ||||
462 | 1520 | 293µs | my $node = shift; | ||
463 | 1520 | 872µs | my $tag = delete $node->{_tag}; | ||
464 | 5820 | 14.9ms | 8600 | 2.88ms | for (keys %{$node}) { /^($TAL:)/ and delete $node->{$_} } # spent 2.17ms making 4300 calls to Petal::Tiny::CORE:regcomp, avg 505ns/call
# spent 714µs making 4300 calls to Petal::Tiny::CORE:match, avg 166ns/call |
465 | 1520 | 888µs | my $open = delete $node->{_open} || 0; | ||
466 | 1520 | 658µs | my $close = delete $node->{_close} || 0; | ||
467 | 1520 | 4.56ms | my $att = join ' ', map { qq|$_="$node->{$_}"| } keys %{$node}; | ||
468 | 1520 | 1.23ms | $open and $close and return $att ? "<$tag $att />" : "<$tag />"; | ||
469 | 1200 | 200µs | $close and return "</$tag>"; | ||
470 | 1200 | 3.00ms | $open and return $att ? "<$tag $att>" : "<$tag>"; | ||
471 | die "There is probably a bug somewhere. A tag that's not and open tag and not a close tag?"; | ||||
472 | } | ||||
473 | |||||
474 | |||||
475 | # spent 105ms (90.1+15.4) within Petal::Tiny::trim which was called 9330 times, avg 11µs/call:
# 4950 times (33.9ms+6.27ms) by Petal::Tiny::resolve at line 362, avg 8µs/call
# 2190 times (25.3ms+4.05ms) by Petal::Tiny::resolve_expression at line 344, avg 13µs/call
# 980 times (10.9ms+2.07ms) by Petal::Tiny::tal_attributes at line 307, avg 13µs/call
# 780 times (14.3ms+2.44ms) by Petal::Tiny::tal_attributes at line 305, avg 21µs/call
# 210 times (4.66ms+341µs) by Petal::Tiny::tal_condition at line 223, avg 24µs/call
# 210 times (965µs+181µs) by Petal::Tiny::tal_condition at line 225, avg 5µs/call
# 10 times (61µs+25µs) by Petal::Tiny::_do_repeat at line 247, avg 9µs/call | ||||
476 | 9330 | 1.75ms | my $string = shift; | ||
477 | 9330 | 1.09ms | $string or return $string; | ||
478 | 9330 | 24.3ms | 9330 | 2.93ms | $string =~ s/\r//g; # spent 2.93ms making 9330 calls to Petal::Tiny::CORE:subst, avg 314ns/call |
479 | 9330 | 28.8ms | 9330 | 2.38ms | $string =~ s/\n/ /g; # spent 2.38ms making 9330 calls to Petal::Tiny::CORE:subst, avg 255ns/call |
480 | 9330 | 16.1ms | 9330 | 3.94ms | $string =~ s/^\s+//; # spent 3.94ms making 9330 calls to Petal::Tiny::CORE:subst, avg 422ns/call |
481 | 9330 | 27.5ms | 9330 | 6.14ms | $string =~ s/\s+$//; # spent 6.14ms making 9330 calls to Petal::Tiny::CORE:subst, avg 658ns/call |
482 | 9330 | 11.5ms | return $string; | ||
483 | } | ||||
484 | |||||
485 | |||||
486 | # spent 54.9ms (46.0+8.88) within Petal::Tiny::has_instructions which was called 3070 times, avg 18µs/call:
# 3070 times (46.0ms+8.88ms) by Petal::Tiny::makeitso_block at line 170, avg 18µs/call | ||||
487 | 3070 | 527µs | my $node = shift; | ||
488 | 3070 | 61.8ms | 28940 | 8.88ms | return grep /^$TAL:/, keys %{$node}; # spent 6.33ms making 14470 calls to Petal::Tiny::CORE:regcomp, avg 437ns/call
# spent 2.56ms making 14470 calls to Petal::Tiny::CORE:match, avg 177ns/call |
489 | } | ||||
490 | |||||
491 | |||||
492 | # spent 1.58s (889ms+690ms) within Petal::Tiny::tag_open which was called 87930 times, avg 18µs/call:
# 78680 times (760ms+529ms) by Petal::Tiny::makeitso at line 104, avg 16µs/call
# 6180 times (76.9ms+84.0ms) by Petal::Tiny::makeitso at line 97, avg 26µs/call
# 3070 times (52.6ms+77.7ms) by Petal::Tiny::makeitso_block at line 167, avg 42µs/call | ||||
493 | 87930 | 13.8ms | my $elem = shift; | ||
494 | 87930 | 9.32ms | my $node = undef; | ||
495 | 87930 | 10.4ms | not defined $elem and confess ('undefined elem'); | ||
496 | |||||
497 | $elem !~ /^<\!/ and | ||||
498 | $elem !~ /^<\// and | ||||
499 | $elem !~ /\/>$/ and | ||||
500 | $elem !~ /^<\?/ and | ||||
501 | 87930 | 728ms | 367410 | 53.5ms | $elem =~ /^</ and do { # spent 53.5ms making 367410 calls to Petal::Tiny::CORE:match, avg 146ns/call |
502 | 21770 | 29.8ms | 21770 | 623ms | my %node = extract_attributes ($elem); # spent 623ms making 21770 calls to Petal::Tiny::extract_attributes, avg 29µs/call |
503 | 21770 | 65.8ms | 21770 | 14.0ms | ($node{_tag}) = $elem =~ /.*?([A-Za-z0-9][A-Za-z0-9_:-]*)/; # spent 14.0ms making 21770 calls to Petal::Tiny::CORE:match, avg 644ns/call |
504 | 21770 | 5.15ms | $node{_open} = 1; | ||
505 | 21770 | 4.56ms | $node{_close} = 0; | ||
506 | 21770 | 7.96ms | $node = \%node; | ||
507 | }; | ||||
508 | 87930 | 185ms | return $node; | ||
509 | } | ||||
510 | |||||
511 | |||||
512 | sub tag_close { | ||||
513 | 82550 | 12.7ms | my $elem = shift; | ||
514 | 82550 | 8.83ms | my $node = undef; | ||
515 | $elem !~ /^<\!/ and | ||||
516 | $elem =~ /^<\// and | ||||
517 | 82550 | 418ms | 184220 | 24.1ms | $elem !~ /\/>$/ and do { # spent 24.1ms making 184220 calls to Petal::Tiny::CORE:match, avg 131ns/call |
518 | 19460 | 4.85ms | my %node = (); | ||
519 | 19460 | 50.1ms | 19460 | 11.8ms | ($node{_tag}) = $elem =~ /.*?([A-Za-z0-9][A-Za-z0-9_:-]*)/; # spent 11.8ms making 19460 calls to Petal::Tiny::CORE:match, avg 607ns/call |
520 | 19460 | 4.29ms | $node{_open} = 0; | ||
521 | 19460 | 3.75ms | $node{_close} = 1; | ||
522 | 19460 | 5.56ms | $node = \%node; | ||
523 | }; | ||||
524 | 82550 | 175ms | return $node; | ||
525 | } | ||||
526 | |||||
527 | |||||
528 | sub tag_self_close { | ||||
529 | 7700 | 1.51ms | my $elem = shift; | ||
530 | 7700 | 1.05ms | my $node = undef; | ||
531 | $elem !~ /^<\!/ and | ||||
532 | $elem !~ /^<\// and | ||||
533 | $elem =~ /\/>$/ and | ||||
534 | 7700 | 71.3ms | 24400 | 4.96ms | $elem =~ /^</ and do { # spent 4.96ms making 24400 calls to Petal::Tiny::CORE:match, avg 203ns/call |
535 | 1520 | 2.70ms | 1520 | 62.3ms | my %node = extract_attributes ($elem); # spent 62.3ms making 1520 calls to Petal::Tiny::extract_attributes, avg 41µs/call |
536 | 1520 | 4.16ms | 1520 | 1.43ms | ($node{_tag}) = $elem =~ /.*?([A-Za-z0-9][A-Za-z0-9_:-]*)/; # spent 1.43ms making 1520 calls to Petal::Tiny::CORE:match, avg 942ns/call |
537 | 1520 | 599µs | $node{_open} = 1; | ||
538 | 1520 | 465µs | $node{_close} = 1; | ||
539 | 1520 | 723µs | $node = \%node; | ||
540 | }; | ||||
541 | 7700 | 27.3ms | return $node; | ||
542 | } | ||||
543 | |||||
544 | |||||
545 | sub extract_attributes { | ||||
546 | 23290 | 3.78ms | my $tag = shift; | ||
547 | 23290 | 185ms | 46580 | 87.0ms | my ($tags) = $tag =~ /$RE_1/g; # spent 71.0ms making 23290 calls to Petal::Tiny::CORE:match, avg 3µs/call
# spent 16.0ms making 23290 calls to Petal::Tiny::CORE:regcomp, avg 686ns/call |
548 | 23290 | 185ms | 46580 | 85.8ms | my %attr = $tag =~ /$RE_2/g; # spent 70.2ms making 23290 calls to Petal::Tiny::CORE:match, avg 3µs/call
# spent 15.5ms making 23290 calls to Petal::Tiny::CORE:regcomp, avg 667ns/call |
549 | 23290 | 20.5ms | foreach my $key (keys %attr) | ||
550 | { | ||||
551 | 35730 | 13.5ms | my $val = $attr{$key}; | ||
552 | 35730 | 110ms | 35730 | 33.5ms | $val =~ s/^(\"|\')//; # spent 33.5ms making 35730 calls to Petal::Tiny::CORE:subst, avg 938ns/call |
553 | 35730 | 109ms | 35730 | 30.6ms | $val =~ s/(\"|\')$//; # spent 30.6ms making 35730 calls to Petal::Tiny::CORE:subst, avg 856ns/call |
554 | 35730 | 29.5ms | $attr{$key} = $val; | ||
555 | } | ||||
556 | |||||
557 | 23290 | 65.6ms | %attr; | ||
558 | } | ||||
559 | |||||
560 | |||||
561 | # spent 9.60ms (8.28+1.32) within Petal::Tiny::xmlencode which was called 2150 times, avg 4µs/call:
# 2150 times (8.28ms+1.32ms) by Petal::Tiny::resolve_expression at line 352, avg 4µs/call | ||||
562 | 2150 | 486µs | my $string = shift; | ||
563 | 2150 | 5.34ms | return $string if !$string or ref $string; | ||
564 | 1120 | 1.53ms | 1120 | 339µs | $string =~ s/&/&/g; # spent 339µs making 1120 calls to Petal::Tiny::CORE:subst, avg 303ns/call |
565 | 1120 | 1.39ms | 1120 | 257µs | $string =~ s/</</g; # spent 257µs making 1120 calls to Petal::Tiny::CORE:subst, avg 230ns/call |
566 | 1120 | 1.39ms | 1120 | 248µs | $string =~ s/>/>/g; # spent 248µs making 1120 calls to Petal::Tiny::CORE:subst, avg 222ns/call |
567 | 1120 | 1.29ms | 1120 | 240µs | $string =~ s/"/"/g; # spent 240µs making 1120 calls to Petal::Tiny::CORE:subst, avg 215ns/call |
568 | 1120 | 1.31ms | 1120 | 233µs | $string =~ s/'/'/g; # spent 233µs making 1120 calls to Petal::Tiny::CORE:subst, avg 208ns/call |
569 | 1120 | 1.46ms | return $string; | ||
570 | } | ||||
571 | |||||
572 | |||||
573 | 1 | 14µs | 1; | ||
574 | |||||
575 | |||||
576 | __END__ | ||||
# spent 275ms within Petal::Tiny::CORE:match which was called 712230 times, avg 386ns/call:
# 367410 times (53.5ms+0s) by Petal::Tiny::tag_open at line 501, avg 146ns/call
# 184220 times (24.1ms+0s) by Petal::Tiny::tag_close at line 517, avg 131ns/call
# 24400 times (4.96ms+0s) by Petal::Tiny::tag_self_close at line 534, avg 203ns/call
# 23290 times (71.0ms+0s) by Petal::Tiny::extract_attributes at line 547, avg 3µs/call
# 23290 times (70.2ms+0s) by Petal::Tiny::extract_attributes at line 548, avg 3µs/call
# 21770 times (14.0ms+0s) by Petal::Tiny::tag_open at line 503, avg 644ns/call
# 19460 times (11.8ms+0s) by Petal::Tiny::tag_close at line 519, avg 607ns/call
# 14470 times (2.56ms+0s) by Petal::Tiny::has_instructions at line 488, avg 177ns/call
# 14440 times (1.49ms+0s) by Petal::Tiny::namespace at line 148, avg 103ns/call
# 4950 times (1.20ms+0s) by Petal::Tiny::resolve at line 364, avg 243ns/call
# 4740 times (1.46ms+0s) by Petal::Tiny::resolve at line 370, avg 308ns/call
# 4300 times (714µs+0s) by Petal::Tiny::node2tag at line 464, avg 166ns/call
# 3870 times (795µs+0s) by Petal::Tiny::_interpolate_dollar at line 135, avg 205ns/call
# 1520 times (1.43ms+0s) by Petal::Tiny::tag_self_close at line 536, avg 942ns/call
# 50 times (15.2ms+0s) by Petal::Tiny::makeitso at line 85, avg 303µs/call
# 50 times (152µs+0s) by Petal::Tiny::new at line 60, avg 3µs/call | |||||
sub Petal::Tiny::CORE:qr; # opcode | |||||
# spent 40.3ms within Petal::Tiny::CORE:regcomp which was called 65402 times, avg 617ns/call:
# 23290 times (16.0ms+0s) by Petal::Tiny::extract_attributes at line 547, avg 686ns/call
# 23290 times (15.5ms+0s) by Petal::Tiny::extract_attributes at line 548, avg 667ns/call
# 14470 times (6.33ms+0s) by Petal::Tiny::has_instructions at line 488, avg 437ns/call
# 4300 times (2.17ms+0s) by Petal::Tiny::node2tag at line 464, avg 505ns/call
# 50 times (233µs+0s) by Petal::Tiny::makeitso at line 85, avg 5µs/call
# once (47µs+0s) by main::BEGIN@2 at line 44
# once (25µs+0s) by main::BEGIN@2 at line 45 | |||||
# spent 87.1ms within Petal::Tiny::CORE:subst which was called 128940 times, avg 675ns/call:
# 35730 times (33.5ms+0s) by Petal::Tiny::extract_attributes at line 552, avg 938ns/call
# 35730 times (30.6ms+0s) by Petal::Tiny::extract_attributes at line 553, avg 856ns/call
# 9330 times (6.14ms+0s) by Petal::Tiny::trim at line 481, avg 658ns/call
# 9330 times (3.94ms+0s) by Petal::Tiny::trim at line 480, avg 422ns/call
# 9330 times (2.93ms+0s) by Petal::Tiny::trim at line 478, avg 314ns/call
# 9330 times (2.38ms+0s) by Petal::Tiny::trim at line 479, avg 255ns/call
# 2530 times (2.44ms+0s) by Petal::Tiny::resolve at line 371, avg 966ns/call
# 2210 times (588µs+0s) by Petal::Tiny::resolve at line 374, avg 266ns/call
# 2190 times (772µs+0s) by Petal::Tiny::resolve_expression at line 346, avg 352ns/call
# 2190 times (584µs+0s) by Petal::Tiny::resolve_expression at line 347, avg 267ns/call
# 2190 times (576µs+0s) by Petal::Tiny::resolve_expression at line 350, avg 263ns/call
# 2190 times (498µs+0s) by Petal::Tiny::resolve_expression at line 349, avg 228ns/call
# 1120 times (339µs+0s) by Petal::Tiny::xmlencode at line 564, avg 303ns/call
# 1120 times (257µs+0s) by Petal::Tiny::xmlencode at line 565, avg 230ns/call
# 1120 times (248µs+0s) by Petal::Tiny::xmlencode at line 566, avg 222ns/call
# 1120 times (240µs+0s) by Petal::Tiny::xmlencode at line 567, avg 215ns/call
# 1120 times (233µs+0s) by Petal::Tiny::xmlencode at line 568, avg 208ns/call
# 980 times (720µs+0s) by Petal::Tiny::tal_attributes at line 309, avg 734ns/call
# 50 times (56µs+0s) by Petal::Tiny::namespace at line 152, avg 1µs/call
# 10 times (39µs+0s) by Petal::Tiny::_interpolate_dollar at line 136, avg 4µs/call
# 10 times (3µs+0s) by Petal::Tiny::_interpolate_dollar at line 137, avg 330ns/call
# 10 times (2µs+0s) by Petal::Tiny::_interpolate_dollar at line 138, avg 180ns/call | |||||
# spent 18µs within Petal::Tiny::CORE:substcont which was called 20 times, avg 925ns/call:
# 20 times (18µs+0s) by Petal::Tiny::_interpolate_dollar at line 136, avg 925ns/call |