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