| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Apache::AxKit::Provider::File::Formatter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use 5.008004; |
|
4
|
1
|
|
|
1
|
|
23102
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
445
|
use Apache::AxKit::Provider::File; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Apache::AxKit::Exception; |
|
8
|
|
|
|
|
|
|
use XML::LibXML; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Apache::AxKit::Provider::File); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.96'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Apache::AxKit::Provider::File::Formatter - An AxKit Provider that can |
|
21
|
|
|
|
|
|
|
use any Formatter API module |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
In your Apache config, you can configure this Provider like this example: |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
PerlHandler AxKit |
|
29
|
|
|
|
|
|
|
AxAddProcessor text/xsl /transforms/xhtml2html.xsl |
|
30
|
|
|
|
|
|
|
AxContentProvider Apache::AxKit::Provider::File::Formatter |
|
31
|
|
|
|
|
|
|
PerlSetVar FormatterModule Formatter::HTML::HTML |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This is an AxKit Provider that may be used to apply any module that |
|
37
|
|
|
|
|
|
|
conforms with the Formatter API (v0.93) to a file. At the time of this |
|
38
|
|
|
|
|
|
|
writing, there are three modules in the C namespace, one |
|
39
|
|
|
|
|
|
|
that can clean existing HTML using L, one for formatting |
|
40
|
|
|
|
|
|
|
the L syntax, and one to add minimal HTML markup to a |
|
41
|
|
|
|
|
|
|
preformatted plain text. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
The Provider can be configured like any other Provider, to apply to a |
|
44
|
|
|
|
|
|
|
directory, a file ending, etc. The only thing that is special about it |
|
45
|
|
|
|
|
|
|
is that it needs a C variable to tell it which module |
|
46
|
|
|
|
|
|
|
will do the actual formatting. It can be set like in the example in |
|
47
|
|
|
|
|
|
|
the SYNOPSIS. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Make sure you have the module you specify installed, otherwise an |
|
50
|
|
|
|
|
|
|
error will result. Also, you may need to copy a supplied XSLT |
|
51
|
|
|
|
|
|
|
stylesheet to an appropriate location from the C |
|
52
|
|
|
|
|
|
|
directory. For example, if you would like to output HTML like in the |
|
53
|
|
|
|
|
|
|
above example, you need the C stylesheet. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_dom { |
|
58
|
|
|
|
|
|
|
my $self = shift; |
|
59
|
|
|
|
|
|
|
my $r = $self->apache_request(); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Let the superclass A:A:P:File handle the request if |
|
62
|
|
|
|
|
|
|
# this is a directory. Nacho++ |
|
63
|
|
|
|
|
|
|
if ($self->_is_dir()) { |
|
64
|
|
|
|
|
|
|
return $self->SUPER::get_strref(); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# From SUPER: |
|
68
|
|
|
|
|
|
|
my $fh = $self->SUPER::get_fh(); |
|
69
|
|
|
|
|
|
|
local $/; |
|
70
|
|
|
|
|
|
|
my $contents = <$fh>; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $whichformatter = $r->dir_config('FormatterModule'); |
|
73
|
|
|
|
|
|
|
AxKit::Debug(5, "Formatter Provider configured to use " . $whichformatter); |
|
74
|
|
|
|
|
|
|
unless ($whichformatter =~ m/^Formatter::\w+::\w+$/) { |
|
75
|
|
|
|
|
|
|
throw Apache::AxKit::Exception::Error( -text => "$whichformatter doesn't look like a formatter to me"); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
eval "use $whichformatter"; |
|
78
|
|
|
|
|
|
|
throw Apache::AxKit::Exception::Error( -text => $whichformatter . " not found, you may need to install it from CPAN") if $@; |
|
79
|
|
|
|
|
|
|
my $formatter = "$whichformatter"->format($contents); |
|
80
|
|
|
|
|
|
|
my $parser = XML::LibXML->new(); |
|
81
|
|
|
|
|
|
|
return $parser->parse_html_string($formatter->document); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_strref { return \ shift->get_dom->toString; } |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_fh { |
|
90
|
|
|
|
|
|
|
throw Apache::AxKit::Exception::IO( -text => "Can't get fh for Formatter" ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The L API specification. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The currently existing Formatters: L, |
|
99
|
|
|
|
|
|
|
L and L. Some |
|
100
|
|
|
|
|
|
|
other Providers may also be of interest: |
|
101
|
|
|
|
|
|
|
L, |
|
102
|
|
|
|
|
|
|
L |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 TODO |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
It should, in principle, be possible to use a chain of Formatter |
|
107
|
|
|
|
|
|
|
modules to process a file in stages. This could be an interesting |
|
108
|
|
|
|
|
|
|
exercise for the future, but then there are also many other pipeline |
|
109
|
|
|
|
|
|
|
based paradigms that me be better suited. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Kjetil Kjernsmo, Ekjetilk@cpan.orgE |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright (C) 2005 by Kjetil Kjernsmo |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
120
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.4 or, |
|
121
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
|
127
|
|
|
|
|
|
|
__END__ |