File Coverage

blib/lib/XML/Genx/Simple.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 2 100.0
condition 4 6 66.6
subroutine 9 9 100.0
pod 1 1 100.0
total 48 50 96.0


line stmt bran cond sub pod time code
1             # @(#) $Id: Simple.pm 1270 2006-10-08 17:29:33Z dom $
2              
3             package XML::Genx::Simple;
4              
5 3     3   1096 use strict;
  3         6  
  3         132  
6 3     3   18 use warnings;
  3         5  
  3         103  
7              
8 3     3   19 use base 'XML::Genx';
  3         6  
  3         9854  
9              
10             our $VERSION = '0.22';
11              
12             sub Element {
13 3     3 1 7966 my $self = shift;
14 3         9 my ( $name, $text, %attrs ) = @_;
15              
16             # Sadly, we can't cache a copy when it's a reference (presumably
17             # an XML::Genx::Element), because we have no easy way to get at
18             # the actual name through the pointer.
19 3 100       13 my $el = ref $name ? $name : $self->_DeclaredElement( $name );
20              
21 3         20 $el->StartElement;
22 3         22 while ( my ( $name, $val ) = each %attrs ) {
23 2         7 my $at = $self->_DeclaredAttribute( $name );
24 2         16 $at->AddAttribute( $val );
25             }
26 3         23 $self->AddText( $text );
27 3         125 $self->EndElement;
28             }
29              
30             sub DESTROY {
31 9     9   5690 my $self = shift;
32             # Clean up any loose pointers we have...
33 9         24 $self->_UndeclareElements;
34 9         21 $self->_UndeclareAttributes;
35              
36             # And pass control back to our parents.
37 9         383 $self->SUPER::DESTROY;
38             }
39              
40             #---------------------------------------------------------------------
41             # Private down here.
42             #---------------------------------------------------------------------
43              
44             {
45             # Because we don't have anywhere inside $self to store the extra
46             # information we want, we need to use some private storage.
47             my %el;
48             sub _DeclaredElement {
49 2     2   3 my $self = shift;
50 2         3 my ( $name ) = @_;
51 2   66     40 return $el{ $self }{ $name } ||= $self->DeclareElement( $name );
52             }
53             sub _UndeclareElements {
54 9     9   12 my $self = shift;
55 9         29 delete $el{ $self };
56             }
57             }
58              
59             {
60             # Ditto about lack of storage in self.
61             my %att;
62             sub _DeclaredAttribute {
63 2     2   3 my $self = shift;
64 2         3 my ( $name ) = @_;
65 2   66     23 return $att{ $self }{ $name } ||= $self->DeclareAttribute( $name );
66             }
67             sub _UndeclareAttributes {
68 9     9   14 my $self = shift;
69 9         22 delete $att{ $self };
70             }
71             }
72              
73             1;
74             __END__