← Index
Performance Profile   « block view • line view • sub view »
For t/test-parsing
  Run on Sun Nov 14 09:49:57 2010
Reported on Sun Nov 14 09:50:11 2010

File /usr/lib/perl5/XML/LibXML/NodeList.pm
Statements Executed 21
Total Time 0.0008629 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sXML::LibXML::NodeList::::BEGINXML::LibXML::NodeList::BEGIN
0000s0sXML::LibXML::NodeList::::appendXML::LibXML::NodeList::append
0000s0sXML::LibXML::NodeList::::get_nodeXML::LibXML::NodeList::get_node
0000s0sXML::LibXML::NodeList::::get_nodelistXML::LibXML::NodeList::get_nodelist
0000s0sXML::LibXML::NodeList::::iteratorXML::LibXML::NodeList::iterator
0000s0sXML::LibXML::NodeList::::newXML::LibXML::NodeList::new
0000s0sXML::LibXML::NodeList::::new_from_refXML::LibXML::NodeList::new_from_ref
0000s0sXML::LibXML::NodeList::::popXML::LibXML::NodeList::pop
0000s0sXML::LibXML::NodeList::::prependXML::LibXML::NodeList::prepend
0000s0sXML::LibXML::NodeList::::pushXML::LibXML::NodeList::push
0000s0sXML::LibXML::NodeList::::shiftXML::LibXML::NodeList::shift
0000s0sXML::LibXML::NodeList::::sizeXML::LibXML::NodeList::size
0000s0sXML::LibXML::NodeList::::string_valueXML::LibXML::NodeList::string_value
0000s0sXML::LibXML::NodeList::::to_booleanXML::LibXML::NodeList::to_boolean
0000s0sXML::LibXML::NodeList::::to_literalXML::LibXML::NodeList::to_literal
0000s0sXML::LibXML::NodeList::::to_numberXML::LibXML::NodeList::to_number
0000s0sXML::LibXML::NodeList::::unshiftXML::LibXML::NodeList::unshift
LineStmts.Exclusive
Time
Avg.Code
1# $Id: NodeList.pm 709 2008-01-29 21:01:32Z pajas $
2
3package XML::LibXML::NodeList;
4328µs9µsuse strict;
# spent 12µs making 1 call to strict::import
53108µs36µsuse XML::LibXML::Boolean;
# spent 8µs making 1 call to import
6326µs9µsuse XML::LibXML::Literal;
# spent 9µs making 1 call to import
7326µs9µsuse XML::LibXML::Number;
# spent 8µs making 1 call to import
8
9357µs19µsuse vars qw ($VERSION);
# spent 29µs making 1 call to vars::import
101700ns700ns$VERSION = "1.66"; # VERSION TEMPLATE: DO NOT CHANGE
11
12use overload
13116µs16µs '""' => \&to_literal,
# spent 53µs making 1 call to overload::import
14 'bool' => \&to_boolean,
152590µs295µs ;
16
17sub new {
18 my $class = shift;
19 bless [@_], $class;
20}
21
22sub new_from_ref {
23 my ($class,$array_ref,$reuse) = @_;
24 return bless $reuse ? $array_ref : [@$array_ref], $class;
25}
26
27sub pop {
28 my $self = CORE::shift;
29 CORE::pop @$self;
30}
31
32sub push {
33 my $self = CORE::shift;
34 CORE::push @$self, @_;
35}
36
37sub append {
38 my $self = CORE::shift;
39 my ($nodelist) = @_;
40 CORE::push @$self, $nodelist->get_nodelist;
41}
42
43sub shift {
44 my $self = CORE::shift;
45 CORE::shift @$self;
46}
47
48sub unshift {
49 my $self = CORE::shift;
50 CORE::unshift @$self, @_;
51}
52
53sub prepend {
54 my $self = CORE::shift;
55 my ($nodelist) = @_;
56 CORE::unshift @$self, $nodelist->get_nodelist;
57}
58
59sub size {
60 my $self = CORE::shift;
61 scalar @$self;
62}
63
64sub get_node {
65 # uses array index starting at 1, not 0
66 # this is mainly because of XPath.
67 my $self = CORE::shift;
68 my ($pos) = @_;
69 $self->[$pos - 1];
70}
71
7211µs1µs*item = \&get_node;
73
74sub get_nodelist {
75 my $self = CORE::shift;
76 @$self;
77}
78
79sub to_boolean {
80 my $self = CORE::shift;
81 return (@$self > 0) ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
82}
83
84# string-value of a nodelist is the string-value of the first node
85sub string_value {
86 my $self = CORE::shift;
87 return '' unless @$self;
88 return $self->[0]->string_value;
89}
90
91sub to_literal {
92 my $self = CORE::shift;
93 return XML::LibXML::Literal->new(
94 join('', grep {defined $_} map { $_->string_value } @$self)
95 );
96}
97
98sub to_number {
99 my $self = CORE::shift;
100 return XML::LibXML::Number->new(
101 $self->to_literal
102 );
103}
104
105sub iterator {
106 warn "this function is obsolete!\nIt was disabled in version 1.54\n";
107 return undef;
108}
109
110110µs10µs1;
111__END__
112
113=head1 NAME
114
115XML::LibXML::NodeList - a list of XML document nodes
116
117=head1 DESCRIPTION
118
119An XML::LibXML::NodeList object contains an ordered list of nodes, as
120detailed by the W3C DOM documentation of Node Lists.
121
122=head1 SYNOPSIS
123
124 my $results = $dom->findnodes('//somepath');
125 foreach my $context ($results->get_nodelist) {
126 my $newresults = $context->findnodes('./other/element');
127 ...
128 }
129
130=head1 API
131
132=head2 new()
133
134You will almost never have to create a new NodeSet object, as it is all
135done for you by XPath.
136
137=head2 get_nodelist()
138
139Returns a list of nodes, the contents of the node list, as a perl list.
140
141=head2 string_value()
142
143Returns the string-value of the first node in the list.
144See the XPath specification for what "string-value" means.
145
146=head2 to_literal()
147
148Returns the concatenation of all the string-values of all
149the nodes in the list.
150
151=head2 get_node($pos)
152
153Returns the node at $pos. The node position in XPath is based at 1, not 0.
154
155=head2 size()
156
157Returns the number of nodes in the NodeSet.
158
159=head2 pop()
160
161Equivalent to perl's pop function.
162
163=head2 push(@nodes)
164
165Equivalent to perl's push function.
166
167=head2 append($nodelist)
168
169Given a nodelist, appends the list of nodes in $nodelist to the end of the
170current list.
171
172=head2 shift()
173
174Equivalent to perl's shift function.
175
176=head2 unshift(@nodes)
177
178Equivalent to perl's unshift function.
179
180=head2 prepend($nodeset)
181
182Given a nodelist, prepends the list of nodes in $nodelist to the front of
183the current list.
184
185=head2 iterator()
186
187Will return a new nodelist iterator for the current nodelist. A
188nodelist iterator is usefull if more complex nodelist processing is
189needed.
190
191=cut