line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::IsItJSON; |
2
|
|
|
|
|
|
|
require Exporter; |
3
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
4
|
|
|
|
|
|
|
@EXPORT_OK = qw/is_it_json/; |
5
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
6
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
7
|
|
|
|
|
|
|
); |
8
|
1
|
|
|
1
|
|
12801
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
10
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
62
|
|
11
|
1
|
|
|
1
|
|
458
|
use JSON::Parse qw/parse_json valid_json/; |
|
1
|
|
|
|
|
666
|
|
|
1
|
|
|
|
|
59
|
|
12
|
1
|
|
|
1
|
|
388
|
use JSON::Create 'create_json'; |
|
1
|
|
|
|
|
702
|
|
|
1
|
|
|
|
|
191
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @responses = ( |
16
|
|
|
|
|
|
|
"That seems to be {X}.", |
17
|
|
|
|
|
|
|
"That might be {X}.", |
18
|
|
|
|
|
|
|
"I'm not sure whether that is {X}.", |
19
|
|
|
|
|
|
|
"It could be {X}.", |
20
|
|
|
|
|
|
|
"OK, it's definitely {X}. Maybe.", |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub babble |
24
|
|
|
|
|
|
|
{ |
25
|
2
|
|
|
2
|
0
|
4
|
my ($what) = @_; |
26
|
2
|
|
|
|
|
28
|
my $response = $responses[int (rand (scalar (@responses)))]; |
27
|
2
|
|
|
|
|
7
|
$response =~ s/\{X\}/$what/; |
28
|
2
|
100
|
|
|
|
7
|
if (rand (2) > 1) { |
29
|
1
|
|
|
|
|
11
|
$response = create_json ($response); |
30
|
|
|
|
|
|
|
} |
31
|
2
|
|
|
|
|
8
|
print "$response\n"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_it_json |
35
|
|
|
|
|
|
|
{ |
36
|
2
|
|
|
2
|
1
|
1253
|
my ($input) = @_; |
37
|
2
|
100
|
|
|
|
6
|
if (valid_json ($input)) { |
38
|
1
|
|
|
|
|
18
|
babble ('JSON'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
1
|
|
|
|
|
37
|
babble ('a Perl data structure'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |