line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::WebService::Tracks::Resource; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
629
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
7
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub readonly { |
12
|
3
|
|
|
3
|
1
|
9
|
my ( $class, @fields ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
212
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
189
|
|
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
6
|
foreach my $field (@fields) { |
17
|
12
|
|
|
|
|
72
|
*{$class . '::' . $field} = sub { |
18
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
0
|
if(@_) { |
21
|
0
|
|
|
|
|
0
|
croak "$field is readonly"; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
0
|
return $self->{$field}; |
24
|
12
|
|
|
|
|
45
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub accessor { |
29
|
3
|
|
|
3
|
1
|
8
|
my ( $class, @fields ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
864
|
|
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
6
|
foreach my $field (@fields) { |
34
|
9
|
|
|
|
|
63
|
*{$class . '::' . $field} = sub { |
35
|
0
|
|
|
0
|
|
|
my $self = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if(@_) { |
38
|
0
|
|
|
|
|
|
$self->{$field} = shift; |
39
|
0
|
|
|
|
|
|
$self->{'_dirty'}{$field} = 1; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
return $self->{$field}; |
42
|
9
|
|
|
|
|
30
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
0
|
|
|
0
|
1
|
|
my ( $class, %params ) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$params{'_dirty'} = {}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return bless \%params, $class; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub destroy { |
55
|
0
|
|
|
0
|
1
|
|
my ( $self, $cb ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->{'parent'}->do_delete([$self->resource_path, $self->id . '.xml'], sub { |
58
|
0
|
|
|
0
|
|
|
return $_[2]; |
59
|
|
|
|
|
|
|
}, sub { |
60
|
0
|
|
|
0
|
|
|
my ( $headers ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if($self->{'parent'}->status_successful($headers->{'Status'})) { |
63
|
0
|
|
|
|
|
|
bless $self, 'AnyEvent::WebService::Tracks::DestroyedResource'; |
64
|
0
|
|
|
|
|
|
$cb->(1); |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$cb->(undef, $headers->{'status'}); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
}); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub update { |
72
|
0
|
|
|
0
|
1
|
|
my ( $self, $cb ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
unless(%{$self->{'_dirty'}}) { |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$cb->($self); |
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $xml = $self->{'parent'}->generate_xml($self->xml_root, |
80
|
0
|
|
|
|
|
|
{ map { $_ => $self->{$_} } keys %{$self->{'_dirty'}} }); |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $outer = $xml; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $url = [$self->resource_path, $self->id . '.xml']; |
84
|
|
|
|
|
|
|
$self->{'parent'}->do_put($url, $xml, sub { |
85
|
0
|
|
|
0
|
|
|
return @_[1, 2]; |
86
|
|
|
|
|
|
|
}, sub { |
87
|
0
|
|
|
0
|
|
|
my ( $xml, $headers ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if($self->{'parent'}->status_successful($headers->{'Status'})) { |
90
|
0
|
0
|
|
|
|
|
if($xml eq 'Success') { |
|
|
0
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->{'parent'}->do_get($url, sub { |
92
|
0
|
|
|
|
|
|
return $_[1]; |
93
|
|
|
|
|
|
|
}, sub { |
94
|
0
|
|
|
|
|
|
my ( $xml ) = @_; |
95
|
0
|
|
|
|
|
|
my $other = $self->{'parent'}->parse_single(ref($self), $xml); |
96
|
0
|
|
|
|
|
|
%$self = %$other; |
97
|
0
|
|
|
|
|
|
$cb->($self); |
98
|
0
|
|
|
|
|
|
}); |
99
|
|
|
|
|
|
|
} elsif($xml eq '') { |
100
|
0
|
|
|
|
|
|
$cb->(undef, 'Update failed'); |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
|
my $other = $self->{'parent'}->parse_single(ref($self), $xml); |
103
|
0
|
|
|
|
|
|
%$self = %$other; |
104
|
0
|
|
|
|
|
|
$cb->($self); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} else { |
107
|
0
|
|
|
|
|
|
$cb->(undef, $headers->{'status'}); |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
}); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |