line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Builder::XML::Utils; |
2
|
6
|
|
|
6
|
|
31
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
173
|
|
3
|
6
|
|
|
6
|
|
26
|
use warnings; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
125
|
|
4
|
6
|
|
|
6
|
|
26
|
use Carp; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
4756
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub build_context { |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $context = { |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
'start' => sub { |
12
|
34
|
|
|
34
|
|
53
|
my ( $self, $param ) = @_; |
13
|
34
|
|
|
|
|
77
|
my $tag = $self->{ns} . $param->{ element }; |
14
|
34
|
|
|
|
|
133
|
my $attr_ref = $param->{ attr }; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$self->__push__( sub { |
17
|
|
|
|
|
|
|
# start building the return string |
18
|
34
|
|
|
|
|
85
|
my $return .= $self->__start_tab__ . q{<}.$tag; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# any spec attrs? |
21
|
34
|
100
|
|
|
|
92
|
if ( $attr_ref->{ _xmlns_ } ) { |
22
|
2
|
|
|
|
|
9
|
$return .= sprintf(' xmlns:%s="%s"', $self->{namespace}, $attr_ref->{ _xmlns_ } ); |
23
|
2
|
|
|
|
|
4
|
delete $attr_ref->{ _xmlns_ }; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# build attributes string |
27
|
34
|
|
|
|
|
35
|
for my $k ( keys %{ $attr_ref } ) { |
|
34
|
|
|
|
|
98
|
|
28
|
13
|
|
|
|
|
71
|
$return .= sprintf( ' %s%s="%s"', $self->{attr_ns}, $k, $attr_ref->{$k} ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
34
|
|
|
|
|
129
|
$return .= q{>} . $self->__open_newline__; |
32
|
34
|
|
|
|
|
85
|
$self->__inc__; |
33
|
|
|
|
|
|
|
|
34
|
34
|
|
|
|
|
235
|
return $return; |
35
|
34
|
|
|
|
|
192
|
}); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
'end' => sub { |
40
|
34
|
|
|
34
|
|
55
|
my ( $self, $param ) = @_; |
41
|
34
|
|
|
|
|
78
|
my $tag = $self->{ns} . $param->{ element }; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->__push__( sub { |
44
|
34
|
|
|
|
|
96
|
$self->__dec__; |
45
|
34
|
|
|
|
|
75
|
$self->__end_tab__ . q{}.$tag.q{>} . $self->__close_newline__; |
46
|
34
|
|
|
|
|
200
|
}); |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
'element' => sub { |
50
|
58
|
|
|
58
|
|
80
|
my ( $self, $param ) = @_; |
51
|
58
|
|
|
|
|
129
|
my $tag = $self->{ns} . $param->{ element }; |
52
|
58
|
|
|
|
|
98
|
my $text = $param->{text}; |
53
|
58
|
100
|
|
|
|
229
|
$text = $self->__cdatax__( $text ) if $self->{ cdata }; |
54
|
|
|
|
|
|
|
|
55
|
58
|
|
|
|
|
74
|
my $attrib = q{}; |
56
|
58
|
|
|
|
|
62
|
for my $k ( keys %{ $param->{ attr } } ) { |
|
58
|
|
|
|
|
193
|
|
57
|
11
|
|
|
|
|
48
|
$attrib .= sprintf( ' %s%s="%s"', $self->{attr_ns}, $k, $param->{attr}->{$k} ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $self->__push__( sub { |
61
|
54
|
|
|
|
|
124
|
$self->__tab__ . q{<}.$tag.$attrib.q{>}.$text.q{}.$tag.q{>} . $self->__close_newline__ |
62
|
58
|
100
|
|
|
|
387
|
}) if $text; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->__push__( sub { |
65
|
4
|
|
|
|
|
10
|
$self->__tab__ . q{<}.$tag.$attrib.$self->{empty_tag} . $self->__close_newline__ |
66
|
|
|
|
|
|
|
}) |
67
|
4
|
|
|
|
|
19
|
}, |
68
|
9
|
|
|
9
|
1
|
93
|
}; |
69
|
|
|
|
|
|
|
|
70
|
9
|
|
|
|
|
142
|
return $context; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_args { |
75
|
9
|
|
|
9
|
1
|
54
|
my ( %arg ) = @_; |
76
|
9
|
100
|
|
|
|
39
|
$arg{ns} = defined $arg{namespace} ? $arg{namespace} . q{:} : q{}; |
77
|
9
|
50
|
|
|
|
27
|
$arg{attr_ns} = defined $arg{attr_namespace} ? ( $arg{attr_namespace} . ':' ) : q{}; |
78
|
9
|
100
|
|
|
|
26
|
$arg{attr_ns} = $arg{qualified_attr} ? $arg{ns} : $arg{attr_ns}; |
79
|
9
|
100
|
|
|
|
27
|
$arg{cr} = $arg{ newline } ? "\n" x $arg{ newline } : q{}; |
80
|
9
|
|
100
|
|
|
54
|
$arg{cdata} ||= 0; |
81
|
|
|
|
|
|
|
|
82
|
9
|
50
|
|
|
|
24
|
$arg{ open_newline } = defined $arg{ open_newline } ? $arg{ open_newline } : 1; |
83
|
9
|
50
|
|
|
|
24
|
$arg{ close_newline } = defined $arg{ close_newline } ? $arg{ close_newline } : 1; |
84
|
|
|
|
|
|
|
|
85
|
9
|
|
100
|
|
|
39
|
$arg{ pre_indent } ||= 0; |
86
|
|
|
|
|
|
|
|
87
|
9
|
|
50
|
|
|
52
|
$arg{ empty_tag } ||= q{ />}; |
88
|
|
|
|
|
|
|
|
89
|
9
|
|
|
|
|
117
|
return %arg; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |