line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Template::Plugin::XML::Style |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Template Toolkit plugin which performs some basic munging of XML |
7
|
|
|
|
|
|
|
# to perform simple stylesheet like transformations. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# AUTHOR |
10
|
|
|
|
|
|
|
# Andy Wardley |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# COPYRIGHT |
13
|
|
|
|
|
|
|
# Copyright (C) 2001-2006 Andy Wardley. All Rights Reserved. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
16
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
#============================================================================ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Template::Plugin::XML::Style; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
87613
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
23
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
24
|
1
|
|
|
1
|
|
5
|
use base 'Template::Plugin::Filter'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
852
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 2.36; |
27
|
|
|
|
|
|
|
our $DYNAMIC = 1; |
28
|
|
|
|
|
|
|
our $FILTER_NAME = 'xmlstyle'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
32
|
|
|
|
|
|
|
# new($context, \%config) |
33
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub init { |
36
|
15
|
|
|
15
|
0
|
71421
|
my $self = shift; |
37
|
15
|
|
66
|
|
|
94
|
my $name = $self->{ _ARGS }->[0] || $FILTER_NAME; |
38
|
15
|
|
|
|
|
64
|
$self->install_filter($name); |
39
|
15
|
|
|
|
|
572
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub filter { |
44
|
15
|
|
|
15
|
0
|
1137
|
my ($self, $text, $args, $config) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# munge start tags |
47
|
15
|
|
|
|
|
123
|
$text =~ s/ < ([\w\.\:]+) ( \s+ [^>]+ )? > |
48
|
31
|
|
|
|
|
83
|
/ $self->start_tag($1, $2, $config) |
49
|
|
|
|
|
|
|
/gsex; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# munge end tags |
52
|
15
|
|
|
|
|
82
|
$text =~ s/ < \/ ([\w\.\:]+) > |
53
|
33
|
|
|
|
|
75
|
/ $self->end_tag($1, $config) |
54
|
|
|
|
|
|
|
/gsex; |
55
|
|
|
|
|
|
|
|
56
|
15
|
|
|
|
|
107
|
return $text; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub start_tag { |
62
|
31
|
|
|
31
|
0
|
71
|
my ($self, $elem, $textattr, $config) = @_; |
63
|
31
|
|
50
|
|
|
122
|
$textattr ||= ''; |
64
|
31
|
|
|
|
|
35
|
my ($pre, $post); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# look for an element match in the stylesheet |
67
|
|
|
|
|
|
|
my $match = $config->{ $elem } |
68
|
31
|
|
100
|
|
|
188
|
|| $self->{ _CONFIG }->{ $elem } |
69
|
|
|
|
|
|
|
|| return "<$elem$textattr>"; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# merge element attributes into copy of stylesheet attributes |
72
|
24
|
100
|
|
|
|
29
|
my $attr = { %{ $match->{ attributes } || { } } }; |
|
24
|
|
|
|
|
148
|
|
73
|
24
|
|
|
|
|
77
|
while ($textattr =~ / \s* ([\w\.\:]+) = " ([^"]+) " /gsx ) { |
74
|
0
|
|
|
|
|
0
|
$attr->{ $1 } = $2; |
75
|
|
|
|
|
|
|
} |
76
|
24
|
|
|
|
|
60
|
$textattr = join(' ', map { "$_=\"$attr->{$_}\"" } keys %$attr); |
|
10
|
|
|
|
|
36
|
|
77
|
24
|
100
|
|
|
|
84
|
$textattr = " $textattr" if $textattr; |
78
|
|
|
|
|
|
|
|
79
|
24
|
|
66
|
|
|
69
|
$elem = $match->{ element } || $elem; |
80
|
24
|
|
100
|
|
|
91
|
$pre = $match->{ pre_start } || ''; |
81
|
24
|
|
100
|
|
|
80
|
$post = $match->{ post_start } || ''; |
82
|
|
|
|
|
|
|
|
83
|
24
|
|
|
|
|
306
|
return "$pre<$elem$textattr>$post"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub end_tag { |
88
|
33
|
|
|
33
|
0
|
64
|
my ($self, $elem, $config) = @_; |
89
|
33
|
|
|
|
|
40
|
my ($pre, $post); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# look for an element match in the stylesheet |
92
|
|
|
|
|
|
|
my $match = $config->{ $elem } |
93
|
33
|
|
100
|
|
|
175
|
|| $self->{ _CONFIG }->{ $elem } |
94
|
|
|
|
|
|
|
|| return "$elem>"; |
95
|
|
|
|
|
|
|
|
96
|
24
|
|
66
|
|
|
56
|
$elem = $match->{ element } || $elem; |
97
|
24
|
|
100
|
|
|
82
|
$pre = $match->{ pre_end } || ''; |
98
|
24
|
|
100
|
|
|
70
|
$post = $match->{ post_end } || ''; |
99
|
|
|
|
|
|
|
|
100
|
24
|
|
|
|
|
113
|
return "$pre$elem>$post"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |