File Coverage

blib/lib/XML/Easy/Element.pm
Criterion Covered Total %
statement 65 66 98.4
branch 15 16 93.7
condition 2 6 33.3
subroutine 19 19 100.0
pod 6 6 100.0
total 107 113 94.6


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             XML::Easy::Element - abstract form of XML element
4              
5             =head1 SYNOPSIS
6              
7             use XML::Easy::Element;
8              
9             $element = XML::Easy::Element->new("a", { href => "#there" },
10             $content);
11              
12             $type_name = $element->type_name;
13             $attributes = $element->attributes;
14             $href = $element->attribute("href");
15             $content = $element->content_object;
16              
17             =head1 DESCRIPTION
18              
19             An object of this class represents an XML element, a node in the tree
20             making up an XML document. This is in an abstract form, intended
21             for general manipulation. It is completely isolated from the textual
22             representation of XML, and holds only the meaningful content of the
23             element. The data in an element object cannot be modified: different
24             data requires the creation of a new object.
25              
26             The properties of an XML element are of three kinds. Firstly, the element
27             has exactly one type, which is referred to by a name. Secondly, the
28             element has a set of zero or more attributes. Each attribute consists of
29             a name, which is unique among the attributes of the element, and a value,
30             which is a string of characters. Finally, the element has content, which
31             is a sequence of zero or more characters and (recursively) elements,
32             interspersed in any fashion.
33              
34             The element type name and attribute names all follow the XML syntax
35             for names. This allows the use of a wide set of Unicode characters,
36             with some restrictions. Attribute values and character content can use
37             almost all Unicode characters, with only a few characters (such as most
38             of the ASCII control characters) prohibited by the specification from
39             being directly represented in XML.
40              
41             This class is not meant to be subclassed. XML elements are unextendable,
42             dumb data. Element objects are better processed using the functions in
43             L than using the methods of this class.
44              
45             =cut
46              
47             package XML::Easy::Element;
48              
49 13     13   4596 { use 5.008; }
  13         48  
50 13     13   71 use warnings;
  13         26  
  13         431  
51 13     13   70 use strict;
  13         27  
  13         439  
52              
53 13     13   77 use XML::Easy::Content 0.007 ();
  13         247  
  13         2491  
54              
55             our $VERSION = "0.011";
56              
57             eval { local $SIG{__DIE__};
58             require XSLoader;
59             XSLoader::load("XML::Easy", $VERSION) unless defined &new;
60             };
61              
62             if($@ eq "") {
63             close(DATA);
64             } else {
65             (my $filename = __FILE__) =~ tr# -~##cd;
66             local $/ = undef;
67             my $pp_code = "#line 83 \"$filename\"\n".;
68             close(DATA);
69             {
70             local $SIG{__DIE__};
71             eval $pp_code;
72             }
73             die $@ if $@ ne "";
74             }
75              
76             *content = \&content_twine;
77              
78             1;
79              
80             __DATA__