line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###############################################################################
|
2
|
|
|
|
|
|
|
#json.pm
|
3
|
|
|
|
|
|
|
#Last Change: 2009-01-21
|
4
|
|
|
|
|
|
|
#Copyright (c) 2009 Marc-Seabstian "Maluku" Lucksch
|
5
|
|
|
|
|
|
|
#Version 0.1
|
6
|
|
|
|
|
|
|
####################
|
7
|
|
|
|
|
|
|
#This file is an addon to the Dotiac::DTL project.
|
8
|
|
|
|
|
|
|
#http://search.cpan.org/perldoc?Dotiac::DTL
|
9
|
|
|
|
|
|
|
#
|
10
|
|
|
|
|
|
|
#json.pm is published under the terms of the MIT license, which basically
|
11
|
|
|
|
|
|
|
#means "Do with it whatever you want". For more information, see the
|
12
|
|
|
|
|
|
|
#license.txt file that should be enclosed with libsofu distributions. A copy of
|
13
|
|
|
|
|
|
|
#the license is (at the time of writing) also available at
|
14
|
|
|
|
|
|
|
#http://www.opensource.org/licenses/mit-license.php .
|
15
|
|
|
|
|
|
|
###############################################################################
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Dotiac::DTL::Addon::json;
|
19
|
1
|
|
|
1
|
|
138546
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
20
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
583
|
|
21
|
|
|
|
|
|
|
require JSON;
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#If it is not already loaded.
|
24
|
|
|
|
|
|
|
require Dotiac::DTL::Filter;
|
25
|
|
|
|
|
|
|
require Dotiac::DTL::Value;
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION=0.1;
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $json=JSON->new();
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#Global options, allow as much as possible.
|
34
|
|
|
|
|
|
|
$json->allow_nonref(1);
|
35
|
|
|
|
|
|
|
$json->allow_blessed(1);
|
36
|
|
|
|
|
|
|
$json->allow_unknown(1);
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $oldjson;
|
40
|
|
|
|
|
|
|
my $oldjson_ascii;
|
41
|
|
|
|
|
|
|
my $oldjson_pretty;
|
42
|
|
|
|
|
|
|
my $oldjson_ascii_pretty;
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub import {
|
45
|
24
|
|
|
24
|
|
24537
|
$oldjson = *{Dotiac::DTL::Filter::json};
|
46
|
24
|
|
|
|
|
52
|
$oldjson_ascii = *{Dotiac::DTL::Filter::json_ascii};
|
47
|
24
|
|
|
|
|
47
|
$oldjson_pretty = *{Dotiac::DTL::Filter::json_pretty};
|
48
|
24
|
|
|
|
|
43
|
$oldjson_ascii_pretty = *{Dotiac::DTL::Filter::json_ascii_pretty};
|
49
|
24
|
|
|
|
|
49
|
*{Dotiac::DTL::Filter::json}=\&json;
|
50
|
24
|
|
|
|
|
42
|
*{Dotiac::DTL::Filter::json_ascii}=\&json_ascii;
|
51
|
24
|
|
|
|
|
35
|
*{Dotiac::DTL::Filter::json_pretty}=\&json_pretty;
|
52
|
24
|
|
|
|
|
52
|
*{Dotiac::DTL::Filter::json_ascii_pretty}=\&json_ascii_pretty;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
sub unimport {
|
56
|
24
|
|
|
24
|
|
5155
|
*{Dotiac::DTL::Filter::json} = $oldjson;
|
57
|
24
|
|
|
|
|
37
|
*{Dotiac::DTL::Filter::json_ascii} = $oldjson_ascii;
|
58
|
24
|
|
|
|
|
37
|
*{Dotiac::DTL::Filter::json_pretty} = $oldjson_pretty;
|
59
|
24
|
|
|
|
|
53
|
*{Dotiac::DTL::Filter::json_ascii_pretty} = $oldjson_ascii_pretty;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub json {
|
63
|
4
|
|
|
4
|
1
|
209
|
my $value=shift;
|
64
|
4
|
|
|
|
|
15
|
$Dotiac::DTL::Addon::json::json->pretty(0);
|
65
|
4
|
|
|
|
|
11
|
$Dotiac::DTL::Addon::json::json->utf8(1);
|
66
|
4
|
|
|
|
|
12
|
return $value->set($json->encode($value->content));
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub json_ascii {
|
70
|
4
|
|
|
4
|
1
|
236
|
my $value=shift;
|
71
|
4
|
|
|
|
|
18
|
$Dotiac::DTL::Addon::json::json->pretty(0);
|
72
|
4
|
|
|
|
|
17
|
$Dotiac::DTL::Addon::json::json->ascii(1);
|
73
|
4
|
|
|
|
|
15
|
return $value->set($json->encode($value->content));
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub json_pretty {
|
77
|
4
|
|
|
4
|
1
|
230
|
my $value=shift;
|
78
|
4
|
|
|
|
|
18
|
$Dotiac::DTL::Addon::json::json->pretty(1);
|
79
|
4
|
|
|
|
|
11
|
$Dotiac::DTL::Addon::json::json->utf8(1);
|
80
|
4
|
|
|
|
|
14
|
return $value->set($json->encode($value->content));
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub json_ascii_pretty {
|
84
|
4
|
|
|
4
|
1
|
260
|
my $value=shift;
|
85
|
4
|
|
|
|
|
18
|
$Dotiac::DTL::Addon::json::json->pretty(1);
|
86
|
4
|
|
|
|
|
10
|
$Dotiac::DTL::Addon::json::json->ascii(1);
|
87
|
4
|
|
|
|
|
15
|
return $value->set($json->encode($value->content));
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
1;
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__
|