line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EntityModel::Definition::XML; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$EntityModel::Definition::XML::VERSION = '0.102'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
use EntityModel::Class { |
6
|
4
|
|
|
|
|
48
|
_isa => [qw{EntityModel::Definition}], |
7
|
4
|
|
|
4
|
|
2275
|
}; |
|
4
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
EntityModel::Definition::XML - definition support for L |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.102 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
See L. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
See L. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
4
|
|
5140
|
use XML::XPath; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use XML::XPath::Node; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 load_file |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub load_file { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
my $path = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $xml = XML::XPath->new(filename => $path) |
41
|
|
|
|
|
|
|
or die 'Unable to load ' . $self . ' from data source ' . $path; |
42
|
|
|
|
|
|
|
return $self->parse($xml); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 load_string |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub load_string { |
50
|
|
|
|
|
|
|
my $self = shift; |
51
|
|
|
|
|
|
|
my $string = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $xml = XML::XPath->new(xml => $string) |
54
|
|
|
|
|
|
|
or die 'Unable to load ' . $self . ' from data source ' . $string; |
55
|
|
|
|
|
|
|
return $self->parse($xml); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 parse |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Parse the L object. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub parse { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
my $xml = shift; |
67
|
|
|
|
|
|
|
my $ns = $xml->find('/entitymodel') // []; |
68
|
|
|
|
|
|
|
my ($structure) = map { $self->parseNode($_) } @$ns; |
69
|
|
|
|
|
|
|
return $structure; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 parseNode |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Parse an individual node in the tree. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub parseNode { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $node = shift; |
81
|
|
|
|
|
|
|
my $name = $node->getName; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Locate all child nodes (eliminating whitespace and other text nodes) |
84
|
|
|
|
|
|
|
my @child = grep { $_->getName } $node->getChildNodes; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my %name; |
87
|
|
|
|
|
|
|
foreach my $c (@child) { |
88
|
|
|
|
|
|
|
my $grandchildCount = scalar(grep { $_->getName } $c->getChildNodes); |
89
|
|
|
|
|
|
|
if($grandchildCount) { |
90
|
|
|
|
|
|
|
push @{$name{$c->getName}}, $self->parseNode($c); |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
$name{$c->getName} = $c->string_value; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
return \%name; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |