line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SWISH::Filters::YAML; |
2
|
1
|
|
|
1
|
|
647
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
3
|
use vars qw( $VERSION @ISA ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
4
|
|
|
|
|
|
|
$VERSION = '0.191'; |
5
|
|
|
|
|
|
|
@ISA = ('SWISH::Filters::Base'); |
6
|
1
|
|
|
1
|
|
4
|
use Data::Dump qw( dump ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
203
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
15
|
my ($class) = @_; |
10
|
1
|
|
|
|
|
8
|
my $self = bless { |
11
|
|
|
|
|
|
|
mimetypes => [ |
12
|
|
|
|
|
|
|
qr!application/x-yaml!, qr!application/yaml!, |
13
|
|
|
|
|
|
|
qr!text/yaml!, qr!text/x-yaml! |
14
|
|
|
|
|
|
|
], |
15
|
|
|
|
|
|
|
}, $class; |
16
|
1
|
|
|
|
|
7
|
return $self->use_modules( 'YAML', ['Search::Tools::XML' => '0.88'], ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub filter { |
20
|
0
|
|
|
0
|
1
|
|
my ( $self, $doc ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# get the raw content |
23
|
0
|
|
|
|
|
|
my $yaml = $doc->fetch_doc_reference; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# convert to perl |
26
|
0
|
|
|
|
|
|
my $perl = YAML::Load($$yaml); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# convert to XML |
29
|
0
|
|
|
|
|
|
my $xml = Search::Tools::XML->perl_to_xml( |
30
|
|
|
|
|
|
|
$perl, |
31
|
|
|
|
|
|
|
{ root => 'doc', |
32
|
|
|
|
|
|
|
wrap_array => 0, |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#warn sprintf("xml: %s\n", Search::Tools::XML->tidy($xml)); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# update the document's content type |
39
|
0
|
|
|
|
|
|
$doc->set_content_type('application/xml'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# If filtered must return either a reference to the doc or a pathname. |
42
|
0
|
|
|
|
|
|
return ( \$xml ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |