File Coverage

blib/lib/XML/Mini/Element/Header.pm
Criterion Covered Total %
statement 40 52 76.9
branch 4 8 50.0
condition 3 12 25.0
subroutine 6 7 85.7
pod 2 3 66.6
total 55 82 67.0


line stmt bran cond sub pod time code
1             package XML::Mini::Element::Header;
2 10     10   64 use strict;
  10         22  
  10         489  
3             $^W = 1;
4              
5 10     10   56 use XML::Mini;
  10         21  
  10         201  
6 10     10   58 use XML::Mini::Element;
  10         21  
  10         390  
7              
8 10     10   53 use vars qw ( $VERSION @ISA );
  10         16  
  10         5660  
9             $VERSION = '1.02';
10             push @ISA, qw ( XML::Mini::Element );
11              
12             sub new
13             {
14 12     12 1 25 my $class = shift;
15 12   33     54 my $name = shift || XML::Mini->Error("Must pass a NAME to XML::Mini::Element::Header::new()");
16            
17 12         26 my $self = {};
18 12   33     104 bless $self, ref $class || $class;
19 12         98 $self->{'_attributes'} = {};
20 12         33 $self->{'_numChildren'} = 0;
21 12         27 $self->{'_numElementChildren'} = 0;
22 12         31 $self->{'_children'} = [];
23 12         29 $self->{'_avoidLoops'} = $XML::Mini::AvoidLoops;
24 12         93 $self->name($name);
25 12         35 return $self;
26             }
27              
28             sub toString
29             {
30 4     4 1 8 my $self = shift;
31 4         6 my $depth = shift;
32            
33 4 50       15 if ($depth == $XML::Mini::NoWhiteSpaces)
34             {
35 0         0 return $self->toStringNoWhiteSpaces();
36             }
37            
38 4         32 my $spaces = $self->_spaceStr($depth);
39            
40 4         19 my $retString = "$spacesname() ;
41            
42 4         9 my $attribString;
43            
44             # make sure version is always first
45 4 100       18 if (exists $self->{'_attributes'}->{'version'})
46             {
47 3         12 $attribString = ' version="' . $self->{'_attributes'}->{'version'} . '"';
48 3         11 delete $self->{'_attributes'}->{'version'};
49             }
50            
51 4         6 foreach my $atName (sort keys %{$self->{'_attributes'}})
  4         21  
52             {
53 3         13 $attribString .= qq| $atName="$self->{'_attributes'}->{$atName}"|;
54             }
55            
56 4 50 33     37 if (defined $attribString && $attribString =~ m|\S|)
57             {
58 4         8 $retString .= $attribString;
59             }
60            
61 4         17 $retString =~ s/\s+$//;
62            
63 4         12 $retString .= "?>\n";
64 4         14 return $retString;
65            
66             }
67              
68              
69             sub toStringNoWhiteSpaces
70             {
71 0     0 0   my $self = shift;
72            
73 0           my $retString = 'name();
74 0           my $attribString;
75 0           foreach my $atName (sort keys %{$self->{'_attributes'}})
  0            
76             {
77 0           $attribString .= qq|$atName="$self->{'_attributes'}->{$atName}" |;
78             }
79 0 0 0       if (defined $attribString && $attribString =~ m|\S|)
80             {
81 0           $retString .= $attribString;
82             }
83 0           $retString =~ s/\s+$//;
84 0           $retString .= "?>";
85 0           return $retString;
86             }
87              
88             1;
89              
90             __END__