← 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:10 2010

File /usr/lib/perl5/XML/LibXML/Literal.pm
Statements Executed 17
Total Time 0.0005467 seconds
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sXML::LibXML::Literal::::BEGINXML::LibXML::Literal::BEGIN
0000s0sXML::LibXML::Literal::::as_stringXML::LibXML::Literal::as_string
0000s0sXML::LibXML::Literal::::as_xmlXML::LibXML::Literal::as_xml
0000s0sXML::LibXML::Literal::::cmpXML::LibXML::Literal::cmp
0000s0sXML::LibXML::Literal::::evaluateXML::LibXML::Literal::evaluate
0000s0sXML::LibXML::Literal::::newXML::LibXML::Literal::new
0000s0sXML::LibXML::Literal::::string_valueXML::LibXML::Literal::string_value
0000s0sXML::LibXML::Literal::::to_booleanXML::LibXML::Literal::to_boolean
0000s0sXML::LibXML::Literal::::to_literalXML::LibXML::Literal::to_literal
0000s0sXML::LibXML::Literal::::to_numberXML::LibXML::Literal::to_number
0000s0sXML::LibXML::Literal::::valueXML::LibXML::Literal::value
LineStmts.Exclusive
Time
Avg.Code
1# $Id: Literal.pm 709 2008-01-29 21:01:32Z pajas $
2
3package XML::LibXML::Literal;
4323µs8µsuse XML::LibXML::Boolean;
# spent 5µs making 1 call to import
5330µs10µsuse XML::LibXML::Number;
# spent 3µs making 1 call to import
6329µs10µsuse strict;
# spent 6µs making 1 call to strict::import
7
8365µs22µsuse vars qw ($VERSION);
# spent 31µs making 1 call to vars::import
91800ns800ns$VERSION = "1.66"; # VERSION TEMPLATE: DO NOT CHANGE
10
11use overload
12119µs19µs '""' => \&value,
# spent 67µs making 1 call to overload::import
132377µs189µs 'cmp' => \&cmp;
14
15sub new {
16 my $class = shift;
17 my ($string) = @_;
18
19# $string =~ s/"/"/g;
20# $string =~ s/'/'/g;
21
22 bless \$string, $class;
23}
24
25sub as_string {
26 my $self = shift;
27 my $string = $$self;
28 $string =~ s/'/'/g;
29 return "'$string'";
30}
31
32sub as_xml {
33 my $self = shift;
34 my $string = $$self;
35 return "<Literal>$string</Literal>\n";
36}
37
38sub value {
39 my $self = shift;
40 $$self;
41}
42
43sub cmp {
44 my $self = shift;
45 my ($cmp, $swap) = @_;
46 if ($swap) {
47 return $cmp cmp $$self;
48 }
49 return $$self cmp $cmp;
50}
51
52sub evaluate {
53 my $self = shift;
54 $self;
55}
56
57sub to_boolean {
58 my $self = shift;
59 return (length($$self) > 0) ? XML::LibXML::Boolean->True : XML::LibXML::Boolean->False;
60}
61
62sub to_number { return XML::LibXML::Number->new($_[0]->value); }
63sub to_literal { return $_[0]; }
64
65sub string_value { return $_[0]->value; }
66
6713µs3µs1;
68__END__
69
70=head1 NAME
71
72XML::LibXML::Literal - Simple string values.
73
74=head1 DESCRIPTION
75
76In XPath terms a Literal is what we know as a string.
77
78=head1 API
79
80=head2 new($string)
81
82Create a new Literal object with the value in $string. Note that &quot; and
83&apos; will be converted to " and ' respectively. That is not part of the XPath
84specification, but I consider it useful. Note though that you have to go
85to extraordinary lengths in an XML template file (be it XSLT or whatever) to
86make use of this:
87
88 <xsl:value-of select="&quot;I'm feeling &amp;quot;sad&amp;quot;&quot;"/>
89
90Which produces a Literal of:
91
92 I'm feeling "sad"
93
94=head2 value()
95
96Also overloaded as stringification, simply returns the literal string value.
97
98=head2 cmp($literal)
99
100Returns the equivalent of perl's cmp operator against the given $literal.
101
102=cut