This file is indexed.

/usr/lib/perl5/XML/Easy/Element.pm is in libxml-easy-perl 0.009-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
=head1 NAME

XML::Easy::Element - abstract form of XML element

=head1 SYNOPSIS

	use XML::Easy::Element;

	$element = XML::Easy::Element->new("a",
			{ href => "#there" }, $content);

	$type_name = $element->type_name;
	$attributes = $element->attributes;
	$href = $element->attribute("href");
	$content = $element->content_object;

=head1 DESCRIPTION

An object of this class represents an XML element, a node in the tree
making up an XML document.  This is in an abstract form, intended
for general manipulation.  It is completely isolated from the textual
representation of XML, and holds only the meaningful content of the
element.  The data in an element object cannot be modified: different
data requires the creation of a new object.

The properties of an XML element are of three kinds.  Firstly, the element
has exactly one type, which is referred to by a name.  Secondly, the
element has a set of zero or more attributes.  Each attribute consists of
a name, which is unique among the attributes of the element, and a value,
which is a string of characters.  Finally, the element has content, which
is a sequence of zero or more characters and (recursively) elements,
interspersed in any fashion.

The element type name and attribute names all follow the XML syntax
for names.  This allows the use of a wide set of Unicode characters,
with some restrictions.  Attribute values and character content can use
almost all Unicode characters, with only a few characters (such as most
of the ASCII control characters) prohibited by the specification from
being directly represented in XML.

This class is not meant to be subclassed.  XML elements are unextendable,
dumb data.  Element objects are better processed using the functions in
L<XML::Easy::NodeBasics> than using the methods of this class.

=cut

package XML::Easy::Element;

{ use 5.008; }
use warnings;
use strict;

use XML::Easy::Content 0.007 ();

our $VERSION = "0.009";

eval { local $SIG{__DIE__};
	require XSLoader;
	XSLoader::load("XML::Easy", $VERSION) unless defined &new;
};

if($@ eq "") {
	close(DATA);
} else {
	(my $filename = __FILE__) =~ tr# -~##cd;
	local $/ = undef;
	my $pp_code = "#line 83 \"$filename\"\n".<DATA>;
	close(DATA);
	{
		local $SIG{__DIE__};
		eval $pp_code;
	}
	die $@ if $@ ne "";
}

*content = \&content_twine;

1;

__DATA__

# Note perl bug: a bug in perl 5.8.{0..6} screws up __PACKAGE__ (used below)
# for the eval.  Explicit package declaration here fixes it.
package XML::Easy::Element;

use Params::Classify 0.000 qw(is_string is_ref);
use XML::Easy::Classify 0.001 qw(check_xml_attributes check_xml_content_object);
use XML::Easy::Syntax 0.000 qw($xml10_name_rx);

BEGIN {
	if(eval { local $SIG{__DIE__};
		require Internals;
		exists &Internals::SetReadOnly;
	}) {
		*_set_readonly = \&Internals::SetReadOnly;
	} else {
		*_set_readonly = sub { };
	}
}

sub _throw_data_error($) {
	my($msg) = @_;
	die "invalid XML data: $msg\n";
}

=head1 CONSTRUCTOR

=over

=item XML::Easy::Element->new(TYPE_NAME, ATTRIBUTES, CONTENT)

Constructs and returns a new element object with the specified properties.
I<TYPE_NAME> must be a string.  I<ATTRIBUTES> must be a reference
to a hash in the same form that is returned by the accessor method
C<attributes> (below).  I<CONTENT> must be a reference to either an
L<XML::Easy::Content> object or a twine array
(see L<XML::Easy::NodeBasics/Twine>).
All are checked for validity, against
the XML 1.0 specification, and the function C<die>s if any are invalid.

=cut

sub new {
	my($class, $type_name, $attrs, $content) = @_;
	_throw_data_error("element type name isn't a string")
		unless is_string($type_name);
	{
		no warnings "utf8";
		_throw_data_error("illegal element type name")
			unless $type_name =~ /\A$xml10_name_rx\z/o;
	}
	_throw_data_error("attribute hash isn't a hash")
		unless is_ref($attrs, "HASH");
	$attrs = { %$attrs };
	_set_readonly(\$_) foreach values %$attrs;
	_set_readonly($attrs);
	check_xml_attributes($attrs);
	if(is_ref($content, "ARRAY")) {
		$content = XML::Easy::Content->new($content);
	} else {
		check_xml_content_object($content);
	}
	my $self = bless([ $type_name, $attrs, $content ], __PACKAGE__);
	_set_readonly(\$_) foreach @$self;
	_set_readonly($self);
	return $self;
}

=back

=head1 METHODS

=over

=item $element->type_name

Returns the element type name, as a string.

=cut

sub type_name { $_[0]->[0] }

=item $element->attributes

Returns a reference to a hash encapsulating the element's attributes.
In the hash, each key is an attribute name, and the corresponding value
is the attribute's value as a string.

The returned hash must not be subsequently modified.  If possible, it
will be marked as read-only in order to prevent modification.  As a side
effect, the read-only-ness may make lookup of any non-existent attribute
generate an exception rather than returning C<undef>.

=cut

sub attributes { $_[0]->[1] }

=item $element->attribute(NAME)

Looks up a specific attribute of the element.
The supplied I<NAME> must be a string containing a valid attribute name.
If there is an attribute by that name then its value is returned,
as a string.  If there is no such attribute then C<undef> is returned.

=cut

sub attribute {
	_throw_data_error("attribute name isn't a string")
		unless is_string($_[1]);
	{
		no warnings "utf8";
		_throw_data_error("illegal attribute name")
			unless $_[1] =~ /\A$xml10_name_rx\z/o;
	}
	return exists($_[0]->[1]->{$_[1]}) ? $_[0]->[1]->{$_[1]} : undef;
}

=item $element->content_object

Returns a reference to an L<XML::Easy::Content> object encapsulating
the element's content.

=cut

sub content_object { $_[0]->[2] }

=item $element->content_twine

Returns a reference to a twine array (see L<XML::Easy::NodeBasics/Twine>)
listing the element's content.

The returned array must not be subsequently modified.  If possible,
it will be marked as read-only in order to prevent modification.

=cut

sub content_twine {
	my $content = $_[0]->[2];
	check_xml_content_object($content);
	return $content->twine;
}

=item $element->content

Deprecated alias for the L</content_twine> method.

=back

=head1 SEE ALSO

L<XML::Easy::Content>,
L<XML::Easy::NodeBasics>

=head1 AUTHOR

Andrew Main (Zefram) <zefram@fysh.org>

=head1 COPYRIGHT

Copyright (C) 2008, 2009 PhotoBox Ltd

Copyright (C) 2009, 2010, 2011 Andrew Main (Zefram) <zefram@fysh.org>

=head1 LICENSE

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1;