line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package XML::XPathExt; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
18457
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
96
|
|
5
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION $hasXSLT $hasXPCtx); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
150
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.01_01'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
544
|
eval 'use XML::LibXSLT; $hasXSLT = 1;'; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
9
|
1
|
|
|
1
|
|
478
|
eval 'use XML::XPathContext; $hasXPCtx = 1;'; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
1
|
50
|
|
1
|
|
1785
|
if ($hasXSLT) { |
13
|
0
|
|
|
|
|
|
my $pkg = caller; |
14
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
221
|
|
15
|
0
|
|
|
|
|
|
for my $prms (@{$pkg . '::EXTENSIONS'}) { |
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
XML::LibXSLT->register_function(@$prms); |
17
|
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
return 1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub registerOnContext { |
23
|
0
|
0
|
|
0
|
0
|
|
die "This method require XML::XPathContext" unless $hasXPCtx; |
24
|
0
|
|
|
|
|
|
my $class = shift; |
25
|
0
|
|
|
|
|
|
my $ctx = shift; |
26
|
0
|
|
|
|
|
|
for my $prms (@{$class . '::EXTENSIONS'}) { |
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$ctx->registerFunctionNS(@$prms); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
XML::XPathExt - Common XPath extension framework |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package XML::XPathExt::MyCoolExtension; |
44
|
|
|
|
|
|
|
use base 'XML::XPathExt'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $ns = "http://perl-xml-rocks.org/java-xml-sucks/"; |
47
|
|
|
|
|
|
|
our @EXTENSIONS = ( [ $ns, 'func1', \&my_func1 ], |
48
|
|
|
|
|
|
|
[ $ns, 'func2', \&my_func2 ], |
49
|
|
|
|
|
|
|
[ $ns, 'func3', \&my_func3 ],); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# your functions... |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 WARNING, HEY, WARNING, YES YOU |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
THIS IS EVEN BEFORE AN ALPHA, IT IS A PROOF OF CONCEPT THAT HAS NOT BEEN |
56
|
|
|
|
|
|
|
TESTED. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
SURGEON GENERAL WARNING: SMOKING PRE-ALPHA MODULES IN PRODUCTION MAY |
59
|
|
|
|
|
|
|
ENSURE JOB SECURITY OF CONSULTANTS. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
USING THIS YOU ARE IN THE DARK, YOU MAY BE EATEN BY A GRUE. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 DESCRIPTION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This is a simple module, the goal of which is to help make XPath extensions |
66
|
|
|
|
|
|
|
consistent in such a way that they work with both XML::LibXSLT and XML::XPathContext. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
I would very much like to support other modules, but that will require more work |
69
|
|
|
|
|
|
|
(mostly around having factory methods that do the right thing to convert to the |
70
|
|
|
|
|
|
|
right objects, which is simple enough but long -- patches welcome). |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Your modules implementing XPath extensions should inherit from this class. It will |
73
|
|
|
|
|
|
|
do two things for them: if c is present, when your class is loaded its |
74
|
|
|
|
|
|
|
extensions will be registered automatically; and you will inherit a C |
75
|
|
|
|
|
|
|
method that when called with an C context object will register all |
76
|
|
|
|
|
|
|
your extensions on it (it can't be done automatically as for C because |
77
|
|
|
|
|
|
|
and instance of the class is required). |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
There's a special variable that should exist and be publically available in your |
80
|
|
|
|
|
|
|
package called C<@EXTENSIONS>. It is an array containing arrayrefs. The synopsis |
81
|
|
|
|
|
|
|
should be pretty clear (hopefully) but in case it is not, each of those arrayrefs |
82
|
|
|
|
|
|
|
contains three items: the namespace URI, the name of the extension function, and |
83
|
|
|
|
|
|
|
a reference to its Perl implementation. Behaviour of extension functions with no |
84
|
|
|
|
|
|
|
defined namespace is not guaranteed and even if it works for you it may very well |
85
|
|
|
|
|
|
|
blow up in other cases. So it is quite a bad idea to not use a namespace. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 GRATUITOUS PONTIFICATING |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
It is recommended that your extension modules be under the C hierarchy, |
90
|
|
|
|
|
|
|
though of course if you have good reasons to put them elsewhere you are totally free |
91
|
|
|
|
|
|
|
to do as you wish. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
It is also B recommended that the namespace you choose for your extensions |
94
|
|
|
|
|
|
|
be an C URI, and not something much harder to retrieve such as a URN. The reason |
95
|
|
|
|
|
|
|
for this is that in the close future (as of this writing, in August 2003) it is likely |
96
|
|
|
|
|
|
|
that the W3C will publish a Note on RDDL indicating documents to be put at the end of |
97
|
|
|
|
|
|
|
a namespace URI. Interesting things that could be useful for this module could be |
98
|
|
|
|
|
|
|
discovered through such a mechanism, using the C module. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Also, if you wish to make your namespace URIs easy to remember for your users, I suggest |
101
|
|
|
|
|
|
|
you use the form C where C matches |
102
|
|
|
|
|
|
|
the one in C. The C has already been registered |
103
|
|
|
|
|
|
|
with the perl.org admin (thanks!) and should RDDL be published then a corresponding server |
104
|
|
|
|
|
|
|
will be made available to the community shortly thereafter to simply RDDL publishing. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Robin Berjon, Erobin.berjon@expway.frE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright 2003 by Robin Berjon |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
115
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |