line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tropo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Use the TropoAPI via Perl |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
629
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
976
|
use Moo; |
|
1
|
|
|
|
|
19888
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
3366
|
use Types::Standard qw(ArrayRef); |
|
1
|
|
|
|
|
79265
|
|
|
1
|
|
|
|
|
13
|
|
10
|
1
|
|
|
1
|
|
2309
|
use Path::Tiny; |
|
1
|
|
|
|
|
16057
|
|
|
1
|
|
|
|
|
76
|
|
11
|
1
|
|
|
1
|
|
12
|
use JSON; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
159
|
use overload '""' => \&json; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.16; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has objects => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => ArrayRef, |
20
|
|
|
|
|
|
|
default => sub { [] }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
for my $subname ( qw(call say ask on wait) ) { |
24
|
|
|
|
|
|
|
my $name = ucfirst $subname; |
25
|
|
|
|
|
|
|
my @parts = qw/Tropo WebAPI/; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $filename = path( @parts, $name . '.pm' ); |
28
|
|
|
|
|
|
|
require $filename; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $module = join '::', @parts, $name; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
173
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
448
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
*{"Tropo::$subname"} = sub { |
35
|
2
|
|
|
2
|
|
95
|
my ($tropo,@params) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
17
|
my $obj = $module->new( @params ); |
38
|
2
|
|
|
|
|
24
|
$tropo->add_object( { $subname => $obj } ); |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
8
|
return $tropo; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub perl { |
45
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
2
|
my @objects; |
48
|
1
|
|
|
|
|
3
|
my $last_type = ''; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
for my $index ( 0 .. $#{ $self->objects } ) { |
|
1
|
|
|
|
|
6
|
|
51
|
2
|
|
|
|
|
760
|
my $object = $self->objects->[$index]; |
52
|
2
|
|
|
|
|
58
|
my $next_object = $self->objects->[$index+1]; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
12
|
my ($type,$obj) = %{ $object }; |
|
2
|
|
|
|
|
6
|
|
55
|
2
|
100
|
|
|
|
5
|
my ($next_type) = %{ $next_object || { '' => ''} }; |
|
2
|
|
|
|
|
14
|
|
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
33
|
|
|
33
|
if ( $type ne $last_type && $type eq $next_type && $type ne 'on' ) { |
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
push @objects, { $type => [ $obj->to_hash ] }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $type ne $last_type && $type ne $next_type || $type eq 'on' ) { |
61
|
2
|
|
|
|
|
17
|
push @objects, { $type => $obj->to_hash }; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
0
|
push @{ $objects[-1]->{$type} }, $obj->to_hash; |
|
0
|
|
|
|
|
0
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
6
|
$last_type = $type; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
5
|
my $data = { |
71
|
|
|
|
|
|
|
tropo => \@objects, |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
3
|
return $data; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub json { |
78
|
1
|
|
|
1
|
0
|
7
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
5
|
my $data = $self->perl; |
81
|
1
|
|
|
|
|
45
|
my $string = JSON->new->encode( $data ); |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
17
|
return $string; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub add_object { |
87
|
2
|
|
|
2
|
0
|
3
|
my ($self, $object) = @_; |
88
|
|
|
|
|
|
|
|
89
|
2
|
50
|
|
|
|
8
|
return if !$object; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
3
|
push @{ $self->{objects} }, $object; |
|
2
|
|
|
|
|
7
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |