| 1 | package XML::Essex::Event; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 10 | $VERSION = 0.000_1; | |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | XML::Essex::Event - ... | ||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | The base event class, also used for unknown event types. | ||||||||||||||||||||||||||||||||||||||
| 14 | Stringifies as $event->type . "()" to indicate an | ||||||||||||||||||||||||||||||||||||||
| 15 | event that has no natural way to represented in XML, or for ones that | ||||||||||||||||||||||||||||||||||||||
| 16 | haven't been handled yet in Essex. | ||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | =head1 Methods | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | =over | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 10 | ▶ | use XML::Essex::Constants qw( debugging ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 10 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||
| 31 | '""' => \&_stringify, | ||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | "cmp" => sub { "$_[0]" cmp "$_[1]" }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | "==" => sub { "$_[0]" == "$_[1]" }, | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 34 | 10 | ); | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | =item new | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | XML::Event->new( a => 1, b => 2 ); | ||||||||||||||||||||||||||||||||||||||
| 39 | XML::Event->new( { a => 1, b => 2 } ); | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | ## in a subclass: | ||||||||||||||||||||||||||||||||||||||
| 42 | sub new { | ||||||||||||||||||||||||||||||||||||||
| 43 | my $self = shift->SUPER::new( @_ ); | ||||||||||||||||||||||||||||||||||||||
| 44 | ... | ||||||||||||||||||||||||||||||||||||||
| 45 | return $self; | ||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | A generic constructor. | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | If a single value is passed in, a reference to it is kept. This must | ||||||||||||||||||||||||||||||||||||||
| 51 | be a HASH for all builtin objects. | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | If an even number of parameters is passed in, treats them as key => | ||||||||||||||||||||||||||||||||||||||
| 54 | value pairs and creates a HASH around them. | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | # $self is a blessed reference to a SCALAR containing another reference | ||||||||||||||||||||||||||||||||||||||
| 59 | # to the data. This double indirection serves several purposes: | ||||||||||||||||||||||||||||||||||||||
| 60 | # | ||||||||||||||||||||||||||||||||||||||
| 61 | # 1. It allows us to overload %{} on $self and still easily get at | ||||||||||||||||||||||||||||||||||||||
| 62 | # the object's data. | ||||||||||||||||||||||||||||||||||||||
| 63 | # 2. It allows upstream filters to send us blessed, tied or overloaded | ||||||||||||||||||||||||||||||||||||||
| 64 | # objects that we operate on and pass on. | ||||||||||||||||||||||||||||||||||||||
| 65 | # 3. It reduces copying, at the cost of increasing the cost of | ||||||||||||||||||||||||||||||||||||||
| 66 | # dereferencing. As many SAX operations are pass through, this may | ||||||||||||||||||||||||||||||||||||||
| 67 | # be a win in most cases. | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 105 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 70 | 105 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | 105 | ▶ | my $self = @_ == 1 | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 73 | ? UNIVERSAL::isa( $_[0], "XML::Essex::Event" ) | ||||||||||||||||||||||||||||||||||||||
| 74 | ? $_[0]->clone | ||||||||||||||||||||||||||||||||||||||
| 75 | : \$_[0] | ||||||||||||||||||||||||||||||||||||||
| 76 | : \{ @_ }; | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 105 | ▶ | bless $self, ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | =item isa | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | Accepts shorthand; if the object's class starts with | ||||||||||||||||||||||||||||||||||||||
| 84 | "XML::Essex::Event::", the parameter is checked against the string after | ||||||||||||||||||||||||||||||||||||||
| 85 | "XML::Essex::Event::". So a XML::Essex::Event::foo->isa( "foo" ) is | ||||||||||||||||||||||||||||||||||||||
| 86 | true (assuming it really is true; in other words, assuming that its @ISA | ||||||||||||||||||||||||||||||||||||||
| 87 | is set properly). | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 871 | ▶ | sub isa { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
isa: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 92 | 871 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 93 | 871 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 871 | ▶ | return (1 | ||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
substr($class, 0, 19) eq 'XML::Essex::Event::' && substr($class, 19) eq $_[0] || $self->SUPER::isa(@_)
substr($class, 0, 19) eq "XML::Essex::Event::" and substr($class, 19) eq $_[0]
MC/DC66%2/3
substr($class, 0, 19) eq 'XML::Essex::Event::' && substr($class, 19) eq $_[0] || $self->SUPER::isa(@_)
substr($class, 0, 19) eq "XML::Essex::Event::"
substr($class, 19) eq $_[0]
$self->SUPER::isa(@_)
Truth table60%3/5
A and B || C
A= substr($class, 0, 19) eq "XML::Essex::Event::"B= substr($class, 19) eq $_[0]C= $self->SUPER::isa(@_)
| |||||||||||||||||||||||||||||||||||||||
| 96 | && substr( $class, 0, 19 ) eq "XML::Essex::Event::" | ||||||||||||||||||||||||||||||||||||||
| 97 | && substr( $class, 19 ) eq $_[0] | ||||||||||||||||||||||||||||||||||||||
| 98 | ) || $self->SUPER::isa( @_ ); | ||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | =item clone | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | my $clone = $e->clone; | ||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | Does a deep copy of an event. Any events that require a deep copy | ||||||||||||||||||||||||||||||||||||||
| 106 | must overload this to provide it, the default action is to just copy the | ||||||||||||||||||||||||||||||||||||||
| 107 | main HASH. | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | 13 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 112 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | 13 | bless \{ %$$self }, ref $self; | |||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||
| 117 | =item type | ||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | Strips all characters up to the "::" and returns the remainder, so, for | ||||||||||||||||||||||||||||||||||||||
| 120 | the XML::Essex::start_document class, this returns "start_document". | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | This I<must> return a valid SAX event name, it is used to figure out | ||||||||||||||||||||||||||||||||||||||
| 123 | how to serialize most event objects. | ||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | This is overloaded in most classes for speed and to allow subclasses to | ||||||||||||||||||||||||||||||||||||||
| 126 | tweak the behavior of a class and still be reported as the proper type. | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | 18 | ▶ | sub type { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 131 | 18 | ( my $r = ref shift ) =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||
| 132 | 18 | $r | |||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | 15 | ▶ | sub _stringify { shift->type() . "()" } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringify: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | =item generate_SAX | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | $e->generate_SAX( $handler ); | ||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | Emits the SAX event(s) necessary to serialize this event object | ||||||||||||||||||||||||||||||||||||||
| 142 | and send them to $handler. $handler will always be defined. | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | Uses the C<type> method to figure out what to send. Some classes | ||||||||||||||||||||||||||||||||||||||
| 145 | (notably XML::Essex::characters) overload this for various reasons. | ||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | Assumes scalar context (which should not cause problems). | ||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | # scalar context is assumed in start_element::generate_SAX. | ||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 243 | ▶ | sub generate_SAX { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_SAX: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 154 | 243 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 155 | 243 | my ( $h ) = @_; | |||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||
| 157 | 243 | my $method = $self->type; | |||||||||||||||||||||||||||||||||||||
| 158 | 243 | warn "Essex $self generating $method()\n" if debugging; | |||||||||||||||||||||||||||||||||||||
| 159 | 243 | return $h->$method( $$self ); | |||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | Copyright 2002, R. Barrie Slaymaker, Jr., All Rights Reserved | ||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||
| 171 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | You may use this module under the terms of the BSD, Artistic, oir GPL licenses, | ||||||||||||||||||||||||||||||||||||||
| 174 | any version. | ||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||
| 178 | Barrie Slaymaker <barries@slaysys.com> | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||
| 182 | 10 | 1; | |||||||||||||||||||||||||||||||||||||