Filename | /usr/lib/x86_64-linux-gnu/perl5/5.20/XML/LibXML/NodeList.pm |
Statements | Executed 16 statements in 1.69ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 933µs | 3.69ms | BEGIN@15 | XML::LibXML::NodeList::
1 | 1 | 1 | 12µs | 23µs | BEGIN@12 | XML::LibXML::NodeList::
1 | 1 | 1 | 10µs | 29µs | BEGIN@23 | XML::LibXML::NodeList::
1 | 1 | 1 | 7µs | 11µs | BEGIN@13 | XML::LibXML::NodeList::
1 | 1 | 1 | 6µs | 21µs | BEGIN@19 | XML::LibXML::NodeList::
1 | 1 | 1 | 4µs | 4µs | BEGIN@16 | XML::LibXML::NodeList::
1 | 1 | 1 | 3µs | 3µs | BEGIN@17 | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | __ANON__[:28] | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | __is_code | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | append | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | foreach | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | get_node | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | get_nodelist | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | grep | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | item | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | iterator | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | map | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | new | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | new_from_ref | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | pop | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | prepend | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | push | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | reduce | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | reverse | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | shift | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | size | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | sort | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | string_value | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | to_boolean | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | to_literal | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | to_literal_delimited | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | to_literal_list | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | to_number | XML::LibXML::NodeList::
0 | 0 | 0 | 0s | 0s | unshift | XML::LibXML::NodeList::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # $Id$ | ||||
2 | # | ||||
3 | # This is free software, you may use it and distribute it under the same terms as | ||||
4 | # Perl itself. | ||||
5 | # | ||||
6 | # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas | ||||
7 | # | ||||
8 | # | ||||
9 | |||||
10 | package XML::LibXML::NodeList; | ||||
11 | |||||
12 | 2 | 23µs | 2 | 34µs | # spent 23µs (12+11) within XML::LibXML::NodeList::BEGIN@12 which was called:
# once (12µs+11µs) by XML::LibXML::BEGIN@27 at line 12 # spent 23µs making 1 call to XML::LibXML::NodeList::BEGIN@12
# spent 11µs making 1 call to strict::import |
13 | 2 | 19µs | 2 | 15µs | # spent 11µs (7+4) within XML::LibXML::NodeList::BEGIN@13 which was called:
# once (7µs+4µs) by XML::LibXML::BEGIN@27 at line 13 # spent 11µs making 1 call to XML::LibXML::NodeList::BEGIN@13
# spent 4µs making 1 call to warnings::import |
14 | |||||
15 | 2 | 650µs | 1 | 3.69ms | # spent 3.69ms (933µs+2.76) within XML::LibXML::NodeList::BEGIN@15 which was called:
# once (933µs+2.76ms) by XML::LibXML::BEGIN@27 at line 15 # spent 3.69ms making 1 call to XML::LibXML::NodeList::BEGIN@15 |
16 | 2 | 18µs | 1 | 4µs | # spent 4µs within XML::LibXML::NodeList::BEGIN@16 which was called:
# once (4µs+0s) by XML::LibXML::BEGIN@27 at line 16 # spent 4µs making 1 call to XML::LibXML::NodeList::BEGIN@16 |
17 | 2 | 19µs | 1 | 3µs | # spent 3µs within XML::LibXML::NodeList::BEGIN@17 which was called:
# once (3µs+0s) by XML::LibXML::BEGIN@27 at line 17 # spent 3µs making 1 call to XML::LibXML::NodeList::BEGIN@17 |
18 | |||||
19 | 2 | 72µs | 2 | 36µs | # spent 21µs (6+15) within XML::LibXML::NodeList::BEGIN@19 which was called:
# once (6µs+15µs) by XML::LibXML::BEGIN@27 at line 19 # spent 21µs making 1 call to XML::LibXML::NodeList::BEGIN@19
# spent 15µs making 1 call to vars::import |
20 | 1 | 400ns | $VERSION = "2.0116"; # VERSION TEMPLATE: DO NOT CHANGE | ||
21 | |||||
22 | use overload | ||||
23 | # spent 29µs (10+19) within XML::LibXML::NodeList::BEGIN@23 which was called:
# once (10µs+19µs) by XML::LibXML::BEGIN@27 at line 29 | ||||
24 | 'bool' => \&to_boolean, | ||||
25 | 'cmp' => sub { | ||||
26 | my($aa, $bb, $order) = @_; | ||||
27 | return ($order ? ("$bb" cmp "$aa") : ("$aa" cmp "$bb")); | ||||
28 | }, | ||||
29 | 2 | 884µs | 2 | 48µs | ; # spent 29µs making 1 call to XML::LibXML::NodeList::BEGIN@23
# spent 19µs making 1 call to overload::import |
30 | |||||
31 | sub new { | ||||
32 | my $class = shift; | ||||
33 | bless [@_], $class; | ||||
34 | } | ||||
35 | |||||
36 | sub new_from_ref { | ||||
37 | my ($class,$array_ref,$reuse) = @_; | ||||
38 | return bless $reuse ? $array_ref : [@$array_ref], $class; | ||||
39 | } | ||||
40 | |||||
41 | sub pop { | ||||
42 | my $self = CORE::shift; | ||||
43 | CORE::pop @$self; | ||||
44 | } | ||||
45 | |||||
46 | sub push { | ||||
47 | my $self = CORE::shift; | ||||
48 | CORE::push @$self, @_; | ||||
49 | } | ||||
50 | |||||
51 | sub append { | ||||
52 | my $self = CORE::shift; | ||||
53 | my ($nodelist) = @_; | ||||
54 | CORE::push @$self, $nodelist->get_nodelist; | ||||
55 | } | ||||
56 | |||||
57 | sub shift { | ||||
58 | my $self = CORE::shift; | ||||
59 | CORE::shift @$self; | ||||
60 | } | ||||
61 | |||||
62 | sub unshift { | ||||
63 | my $self = CORE::shift; | ||||
64 | CORE::unshift @$self, @_; | ||||
65 | } | ||||
66 | |||||
67 | sub prepend { | ||||
68 | my $self = CORE::shift; | ||||
69 | my ($nodelist) = @_; | ||||
70 | CORE::unshift @$self, $nodelist->get_nodelist; | ||||
71 | } | ||||
72 | |||||
73 | sub size { | ||||
74 | my $self = CORE::shift; | ||||
75 | scalar @$self; | ||||
76 | } | ||||
77 | |||||
78 | sub get_node { | ||||
79 | # uses array index starting at 1, not 0 | ||||
80 | # this is mainly because of XPath. | ||||
81 | my $self = CORE::shift; | ||||
82 | my ($pos) = @_; | ||||
83 | $self->[$pos - 1]; | ||||
84 | } | ||||
85 | |||||
86 | sub item | ||||
87 | { | ||||
88 | my ($self, $pos) = @_; | ||||
89 | return $self->[$pos]; | ||||
90 | } | ||||
91 | |||||
92 | sub get_nodelist { | ||||
93 | my $self = CORE::shift; | ||||
94 | @$self; | ||||
95 | } | ||||
96 | |||||
97 | sub to_boolean { | ||||
98 | my $self = CORE::shift; | ||||
99 | return (@$self > 0) ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False; | ||||
100 | } | ||||
101 | |||||
102 | # string-value of a nodelist is the string-value of the first node | ||||
103 | sub string_value { | ||||
104 | my $self = CORE::shift; | ||||
105 | return '' unless @$self; | ||||
106 | return $self->[0]->string_value; | ||||
107 | } | ||||
108 | |||||
109 | sub to_literal { | ||||
110 | my $self = CORE::shift; | ||||
111 | return XML::LibXML::Literal->new( | ||||
112 | join('', CORE::grep {defined $_} CORE::map { $_->string_value } @$self) | ||||
113 | ); | ||||
114 | } | ||||
115 | |||||
116 | sub to_literal_delimited { | ||||
117 | my $self = CORE::shift; | ||||
118 | return XML::LibXML::Literal->new( | ||||
119 | join(CORE::shift, CORE::grep {defined $_} CORE::map { $_->string_value } @$self) | ||||
120 | ); | ||||
121 | } | ||||
122 | |||||
123 | sub to_literal_list { | ||||
124 | my $self = CORE::shift; | ||||
125 | my @nodes = CORE::map{ XML::LibXML::Literal->new($_->string_value())->value() } @{$self}; | ||||
126 | |||||
127 | if (wantarray) { | ||||
128 | return( @nodes ); | ||||
129 | } | ||||
130 | return( \@nodes ); | ||||
131 | } | ||||
132 | |||||
133 | sub to_number { | ||||
134 | my $self = CORE::shift; | ||||
135 | return XML::LibXML::Number->new( | ||||
136 | $self->to_literal | ||||
137 | ); | ||||
138 | } | ||||
139 | |||||
140 | sub iterator { | ||||
141 | warn "this function is obsolete!\nIt was disabled in version 1.54\n"; | ||||
142 | return undef; | ||||
143 | } | ||||
144 | |||||
145 | sub map { | ||||
146 | my $self = CORE::shift; | ||||
147 | my $sub = __is_code(CORE::shift); | ||||
148 | local $_; | ||||
149 | my @results = CORE::map { @{[ $sub->($_) ]} } @$self; | ||||
150 | return unless defined wantarray; | ||||
151 | return wantarray ? @results : (ref $self)->new(@results); | ||||
152 | } | ||||
153 | |||||
154 | sub grep { | ||||
155 | my $self = CORE::shift; | ||||
156 | my $sub = __is_code(CORE::shift); | ||||
157 | local $_; | ||||
158 | my @results = CORE::grep { $sub->($_) } @$self; | ||||
159 | return unless defined wantarray; | ||||
160 | return wantarray ? @results : (ref $self)->new(@results); | ||||
161 | } | ||||
162 | |||||
163 | sub sort { | ||||
164 | my $self = CORE::shift; | ||||
165 | my $sub = __is_code(CORE::shift); | ||||
166 | my @results = CORE::sort { $sub->($a,$b) } @$self; | ||||
167 | return wantarray ? @results : (ref $self)->new(@results); | ||||
168 | } | ||||
169 | |||||
170 | sub foreach { | ||||
171 | my $self = CORE::shift; | ||||
172 | my $sub = CORE::shift; | ||||
173 | |||||
174 | foreach my $item (@$self) | ||||
175 | { | ||||
176 | local $_ = $item; | ||||
177 | $sub->($item); | ||||
178 | } | ||||
179 | |||||
180 | return wantarray ? @$self : $self; | ||||
181 | } | ||||
182 | |||||
183 | sub reverse { | ||||
184 | my $self = CORE::shift; | ||||
185 | my @results = CORE::reverse @$self; | ||||
186 | return wantarray ? @results : (ref $self)->new(@results); | ||||
187 | } | ||||
188 | |||||
189 | sub reduce { | ||||
190 | my $self = CORE::shift; | ||||
191 | my $sub = __is_code(CORE::shift); | ||||
192 | |||||
193 | my @list = @$self; | ||||
194 | CORE::unshift @list, $_[0] if @_; | ||||
195 | |||||
196 | my $a = CORE::shift(@list); | ||||
197 | foreach my $b (@list) | ||||
198 | { | ||||
199 | $a = $sub->($a, $b); | ||||
200 | } | ||||
201 | return $a; | ||||
202 | } | ||||
203 | |||||
204 | sub __is_code { | ||||
205 | my ($code) = @_; | ||||
206 | |||||
207 | if (ref $code eq 'CODE') { | ||||
208 | return $code; | ||||
209 | } | ||||
210 | |||||
211 | # There are better ways of doing this, but here I've tried to | ||||
212 | # avoid adding any additional external dependencies. | ||||
213 | # | ||||
214 | if (UNIVERSAL::can($code, 'can') # is blessed (sort of) | ||||
215 | and overload::Overloaded($code) # is overloaded | ||||
216 | and overload::Method($code, '&{}')) { # overloads '&{}' | ||||
217 | return $code; | ||||
218 | } | ||||
219 | |||||
220 | # The other possibility is that $code is a coderef, but is | ||||
221 | # blessed into a class that doesn't overload '&{}'. In which | ||||
222 | # case... well, I'm stumped! | ||||
223 | |||||
224 | die "Not a subroutine reference\n"; | ||||
225 | } | ||||
226 | |||||
227 | 1 | 2µs | 1; | ||
228 | __END__ |