line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::BigDoor::Resource; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
74
|
use strict; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
776
|
|
4
|
11
|
|
|
11
|
|
60
|
use warnings; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
346
|
|
5
|
11
|
|
|
11
|
|
67
|
use Carp; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
805
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#use Smart::Comments -ENV; |
8
|
|
|
|
|
|
|
|
9
|
11
|
|
|
11
|
|
54
|
use base qw(Class::Accessor); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
8876
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->follow_best_practice; |
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
13
|
|
|
|
|
|
|
qw(created_timestamp modified_timestamp pub_title pub_description end_user_title end_user_description resource_name) |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
62
|
|
|
62
|
1
|
196317
|
my ( $class, $args ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
## new... |
20
|
62
|
|
|
|
|
127
|
my $self = {}; |
21
|
|
|
|
|
|
|
## args: $args |
22
|
|
|
|
|
|
|
### check: ref( $args ) eq 'HASH' |
23
|
|
|
|
|
|
|
|
24
|
62
|
|
|
|
|
114
|
foreach my $k ( keys %{$args} ) { |
|
62
|
|
|
|
|
330
|
|
25
|
|
|
|
|
|
|
## key: $k |
26
|
|
|
|
|
|
|
## val: $args->{$k} |
27
|
|
|
|
|
|
|
# FIXME restrict allowed key names |
28
|
505
|
|
|
|
|
930
|
$self->{$k} = $args->{$k}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
62
|
|
|
|
|
230
|
bless( $self, $class ); |
32
|
62
|
|
|
|
|
260
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub end_point { |
36
|
70
|
|
|
70
|
1
|
156
|
my ( $self ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
70
|
|
|
|
|
322
|
my $ep = $self->_end_point; |
39
|
|
|
|
|
|
|
|
40
|
70
|
100
|
|
|
|
330
|
if ( $self->_parent_end_point() ) { |
41
|
9
|
|
|
|
|
34
|
$ep = sprintf '%s/%s/%s', |
42
|
|
|
|
|
|
|
$self->_parent_end_point(), |
43
|
|
|
|
|
|
|
$self->{$self->_parent_id_attr}, |
44
|
|
|
|
|
|
|
$self->_end_point(); |
45
|
|
|
|
|
|
|
### ep with parent: $ep |
46
|
|
|
|
|
|
|
} |
47
|
70
|
|
|
|
|
164
|
return $ep; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub all { |
51
|
21
|
|
|
21
|
1
|
41900
|
my ( $self, $client ) = @_; |
52
|
21
|
|
|
|
|
136
|
my $ep = $self->end_point(); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
## end_point: $ep |
55
|
|
|
|
|
|
|
### check: defined $ep |
56
|
21
|
|
|
|
|
130
|
my $data = $client->GET( $ep ); |
57
|
21
|
|
|
|
|
50
|
my @all; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
### data: $data |
60
|
|
|
|
|
|
|
|
61
|
21
|
|
|
|
|
44
|
foreach my $object ( @{@$data[0]} ) { |
|
21
|
|
|
|
|
73
|
|
62
|
|
|
|
|
|
|
### object: $object |
63
|
25
|
|
|
|
|
105
|
push @all, $self->new( $object ); |
64
|
|
|
|
|
|
|
### next... |
65
|
|
|
|
|
|
|
} |
66
|
21
|
|
|
|
|
165
|
return [@all]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub load { |
70
|
14
|
|
|
14
|
1
|
93957
|
my ( $self, $client, $id ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
14
|
100
|
66
|
|
|
103
|
if ( !defined $id && !ref $self ) { |
73
|
3
|
|
|
|
|
85
|
croak "Should pass object ID\n"; |
74
|
|
|
|
|
|
|
} |
75
|
11
|
|
|
|
|
75
|
my $ep = $self->_end_point(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
## end_point: $ep |
78
|
|
|
|
|
|
|
|
79
|
11
|
100
|
|
|
|
63
|
$id = $self->get_id unless defined $id; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
### check: defined $ep |
82
|
|
|
|
|
|
|
### check: defined $id |
83
|
|
|
|
|
|
|
### end_point: sprintf '%s/%s', $ep, $id |
84
|
11
|
|
|
|
|
149
|
my $data = $client->GET( sprintf '%s/%s', $ep, $id ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
### data: $data |
87
|
|
|
|
|
|
|
### check: defined $data |
88
|
|
|
|
|
|
|
|
89
|
11
|
100
|
|
|
|
144
|
if ( ref $self ) { |
90
|
4
|
|
|
|
|
10
|
foreach my $k ( keys %{$data->[0]} ) { |
|
4
|
|
|
|
|
24
|
|
91
|
|
|
|
|
|
|
## key: $k |
92
|
|
|
|
|
|
|
## val: $args->{$k} |
93
|
|
|
|
|
|
|
# FIXME restrict allowed key names |
94
|
50
|
|
|
|
|
101
|
$self->{$k} = $data->[0]->{$k}; |
95
|
|
|
|
|
|
|
} |
96
|
4
|
|
|
|
|
28
|
return $self; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
76
|
return $self->new( @$data[0] ); |
100
|
|
|
|
|
|
|
} ## end sub load |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub save { |
103
|
26
|
|
|
26
|
1
|
54145
|
my ( $self, $client ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
26
|
|
|
|
|
179
|
my $ep = $self->end_point(); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
### end_point: $ep |
108
|
|
|
|
|
|
|
### check: defined $ep |
109
|
|
|
|
|
|
|
|
110
|
26
|
|
|
|
|
55
|
my $payload; |
111
|
26
|
|
|
|
|
50
|
foreach my $k ( keys %{$self} ) { |
|
26
|
|
|
|
|
163
|
|
112
|
118
|
100
|
|
|
|
363
|
next if ref $self->{$k}; |
113
|
117
|
|
|
|
|
269
|
$payload->{$k} = $self->{$k}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
26
|
|
|
|
|
62
|
my $result; |
117
|
|
|
|
|
|
|
|
118
|
26
|
100
|
|
|
|
129
|
if ( defined $self->get_id ) { |
119
|
6
|
|
|
|
|
130
|
$result = |
120
|
|
|
|
|
|
|
$client->PUT( sprintf( '%s/%s', $ep, $self->get_id ), {format => 'json'}, $payload ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
20
|
|
|
|
|
494
|
$result = $client->POST( $ep, {format => 'json'}, $payload ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
### result: $result->[0] |
126
|
26
|
|
|
|
|
95
|
foreach my $k ( keys %{$result->[0]} ) { |
|
26
|
|
|
|
|
154
|
|
127
|
|
|
|
|
|
|
## key: $k |
128
|
|
|
|
|
|
|
## val: $args->{$k} |
129
|
|
|
|
|
|
|
# FIXME restrict allowed key names |
130
|
336
|
|
|
|
|
699
|
$self->{$k} = $result->[0]{$k}; |
131
|
|
|
|
|
|
|
} |
132
|
26
|
|
|
|
|
213
|
return $self; |
133
|
|
|
|
|
|
|
} ## end sub save |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub remove { |
136
|
25
|
|
|
25
|
1
|
45096
|
my ( $self, $client, $id ) = @_; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
### remove... |
139
|
11
|
|
|
11
|
|
77
|
use Data::Dumper; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
3685
|
|
140
|
|
|
|
|
|
|
### self: Dumper( $self ) |
141
|
25
|
|
|
|
|
114
|
my $ep = $self->end_point(); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
### check: defined $ep |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
### check: defined $id |
146
|
25
|
50
|
33
|
|
|
288
|
$id = $self->get_id if ( ref $self && !defined $id ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
### ref: ref $self |
149
|
|
|
|
|
|
|
### check: defined $id |
150
|
|
|
|
|
|
|
### end_point: sprintf '%s/%s', $ep, $id |
151
|
|
|
|
|
|
|
|
152
|
25
|
|
|
|
|
449
|
$client->DELETE( sprintf '%s/%s', $ep, $id ); |
153
|
25
|
|
|
|
|
83
|
return; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _parent_end_point { |
157
|
61
|
|
|
61
|
|
186
|
return; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _end_point { |
161
|
102
|
|
|
102
|
|
226
|
my ( $self ) = @_; |
162
|
|
|
|
|
|
|
|
163
|
102
|
50
|
|
|
|
381
|
croak "Need object or class named" unless defined $self; |
164
|
|
|
|
|
|
|
|
165
|
102
|
100
|
|
|
|
414
|
$self = ref $self if ref $self; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
### self1: $self |
168
|
|
|
|
|
|
|
|
169
|
102
|
50
|
|
|
|
602
|
if ( $self =~ /WWW::BigDoor::(\w+)/x ) { |
170
|
102
|
|
|
|
|
310
|
$self = $1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
102
|
|
|
|
|
340
|
$self =~ s/([A-Z]+)([A-Z][a-z])/$1_$2/xg; |
174
|
102
|
|
|
|
|
827
|
$self =~ s/([a-z\d])([A-Z])/$1_$2/xg; |
175
|
|
|
|
|
|
|
|
176
|
102
|
50
|
|
|
|
281
|
confess "Can\'t detect class name $self" unless defined $self; |
177
|
|
|
|
|
|
|
|
178
|
102
|
|
|
|
|
407
|
return lc $self; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
__END__ |