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