line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /local/CPAN/Apache-AxKit-Language-XSP-ObjectTaglib/lib/Apache/AxKit/Language/XSP/ObjectTaglib.pm 1518 2008-03-08T22:17:31.628142Z claco $ |
2
|
|
|
|
|
|
|
package Apache::AxKit::Language::XSP::ObjectTaglib; |
3
|
1
|
|
|
1
|
|
38810
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw/@ISA $VERSION @EXPORT/; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
68
|
|
6
|
1
|
|
|
1
|
|
7746
|
use AxKit; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Apache::AxKit::Language::XSP; |
8
|
|
|
|
|
|
|
$VERSION = "0.09000"; |
9
|
|
|
|
|
|
|
use Exporter; |
10
|
|
|
|
|
|
|
@ISA = ('Apache::AxKit::Language::XSP', 'Exporter'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT = qw(parse_start parse_end); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %stacks; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse_char { |
17
|
|
|
|
|
|
|
my ($e, $text) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$text =~ s/^\s*//; |
20
|
|
|
|
|
|
|
$text =~ s/\s*$//; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return '' unless $text; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$text =~ s/\|/\\\|/g; |
25
|
|
|
|
|
|
|
return ". q|$text|"; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub parse_start { |
29
|
|
|
|
|
|
|
my ($e, $tag, %attr) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: parse_start called on tag '$tag'"); |
32
|
|
|
|
|
|
|
$tag =~ s/-/_/g; |
33
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: tag name cleaned to '$tag'"); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $ns = $e->{Current_Element}->{NamespaceURI}; |
37
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: current namespace is '$ns'"); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $where = $Apache::AxKit::Language::XSP::tag_lib{ $ns }; |
40
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: current taglib is '$where'"); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
push @{$stacks{$where}}, $tag; |
43
|
|
|
|
|
|
|
my ($safe_where, @specification); |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
no strict 'refs'; @specification = @{"${where}::specification"}; |
46
|
|
|
|
|
|
|
die "No specification found in $where!" unless @specification; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
($safe_where = lc $where) =~ s/::/_/g; |
50
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: taglib cleaned to '$safe_where'"); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
if ($AxKit::Cfg->DebugLevel() > 0) { |
53
|
|
|
|
|
|
|
for (keys %attr) { |
54
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: tag attribute $_=" . $attr{$_}); |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
s/\|//g for %attr; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
AxKit::Debug(5, 'ObjectTaglib: looping through specification'); |
61
|
|
|
|
|
|
|
for (@specification) { |
62
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: specification item '" . $_->{tag} . "'"); |
63
|
|
|
|
|
|
|
if ($tag ne $_->{tag}) { |
64
|
|
|
|
|
|
|
AxKit::Debug(5, |
65
|
|
|
|
|
|
|
"ObjectTaglib: skipping tag specification '$tag'!=" . $_->{tag}); |
66
|
|
|
|
|
|
|
next; |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if (defined $_->{context} ) { |
70
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: context '" . $_->{context} . "'"); |
71
|
|
|
|
|
|
|
next unless $_->{context} eq $stacks{$where}->[-2]; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
if ($_->{type} eq 'special') { |
75
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: calling start method '" . |
76
|
|
|
|
|
|
|
$_->{start} . "'"); |
77
|
|
|
|
|
|
|
return $_->{start}->($e, $tag, %attr) |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
if ($_->{type} eq "loop") { |
81
|
|
|
|
|
|
|
$e->manage_text(0); |
82
|
|
|
|
|
|
|
my $iterator = $_->{iterator}; |
83
|
|
|
|
|
|
|
my $target = $_->{target}; |
84
|
|
|
|
|
|
|
return <
|
85
|
|
|
|
|
|
|
for my \$_xsp_${safe_where}_$iterator (\$_xsp_${safe_where}_${target}->$tag) { |
86
|
|
|
|
|
|
|
EOF |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
$e->start_expr($tag) unless $_->{type} eq "as_xml"; |
89
|
|
|
|
|
|
|
return ''; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
die "Unknown start tag $tag\n"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub parse_end { |
95
|
|
|
|
|
|
|
my ($e, $tag, %attr) = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: parse_end called on tag '$tag'"); |
98
|
|
|
|
|
|
|
$tag =~ s/-/_/g; |
99
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: tag name cleaned to '$tag'"); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $where = $AxKit::XSP::TaglibPkg; |
102
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: current namespace is '$where'"); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
pop @{$stacks{$where}}; |
105
|
|
|
|
|
|
|
my ($safe_where, @specification); |
106
|
|
|
|
|
|
|
{ no strict 'refs'; @specification = @{"${where}::specification"}; } |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
($safe_where = lc $where) =~ s/::/_/g; |
109
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: taglib cleaned to '$safe_where'"); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ($AxKit::Cfg->DebugLevel() > 0) { |
112
|
|
|
|
|
|
|
for (keys %attr) { |
113
|
|
|
|
|
|
|
AxKit::Debug(5, "ObjectTaglib: tag attribute $_=" . $attr{$_}); |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
for (@specification) { |
118
|
|
|
|
|
|
|
next unless $tag eq $_->{tag}; |
119
|
|
|
|
|
|
|
if (defined $_->{context} ) { |
120
|
|
|
|
|
|
|
next unless $_->{context} eq $stacks{$where}->[-1]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
return $_->{end}->($e, $tag, %attr) |
124
|
|
|
|
|
|
|
if $_->{type} eq 'special'; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $target = $_->{target}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if ($_->{type} eq "loop") { |
129
|
|
|
|
|
|
|
$e->manage_text(0); |
130
|
|
|
|
|
|
|
return "}"; |
131
|
|
|
|
|
|
|
} elsif ($_->{type} eq "as_xml") { |
132
|
|
|
|
|
|
|
$e->manage_text(0); |
133
|
|
|
|
|
|
|
my $util_include_expr = { |
134
|
|
|
|
|
|
|
Name => 'include-expr', |
135
|
|
|
|
|
|
|
NamespaceURI => $AxKit::XSP::Util::NS, |
136
|
|
|
|
|
|
|
Attributes => [], |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
my $xsp_expr = { |
139
|
|
|
|
|
|
|
Name => 'expr', |
140
|
|
|
|
|
|
|
NamespaceURI => $AxKit::XSP::Core::NS, |
141
|
|
|
|
|
|
|
Attributes => [], |
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
$e->start_element($util_include_expr); |
144
|
|
|
|
|
|
|
$e->start_element($xsp_expr); |
145
|
|
|
|
|
|
|
$e->append_to_script(<
|
146
|
|
|
|
|
|
|
''.\$_xsp_${safe_where}_$target->$tag(). |
147
|
|
|
|
|
|
|
'' |
148
|
|
|
|
|
|
|
EOF |
149
|
|
|
|
|
|
|
$e->end_element($xsp_expr); |
150
|
|
|
|
|
|
|
$e->end_element($util_include_expr); |
151
|
|
|
|
|
|
|
return '' |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$e->append_to_script( |
155
|
|
|
|
|
|
|
"(\$_xsp_${safe_where}_$target->" . ($_->{key} || $tag) . "()" . |
156
|
|
|
|
|
|
|
($_->{notnull} && '|| \'\'').");" |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$e->end_expr(); |
160
|
|
|
|
|
|
|
return ""; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
die "Unknown end tag $tag\n"; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
__END__ |