| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::CRUST::Result; |
|
2
|
1
|
|
|
1
|
|
5
|
use base qw(Class::Accessor); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
806
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use strict; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.7'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( |
|
10
|
|
|
|
|
|
|
result |
|
11
|
|
|
|
|
|
|
crust |
|
12
|
|
|
|
|
|
|
)); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
|
|
|
|
|
|
my ($class, $h, $crust) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $self = bless {}, $class; |
|
19
|
|
|
|
|
|
|
$self->result($h); |
|
20
|
|
|
|
|
|
|
$self->crust($crust); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub string { |
|
28
|
|
|
|
|
|
|
my $self = shift; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return scalar $self->result; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Stringify |
|
34
|
|
|
|
|
|
|
use overload |
|
35
|
|
|
|
|
|
|
'""' => sub { shift->string }, |
|
36
|
|
|
|
|
|
|
fallback => 1; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
41
|
|
|
|
|
|
|
my $self = shift; |
|
42
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Don't override DESTROY |
|
45
|
|
|
|
|
|
|
return if $AUTOLOAD =~ /::DESTROY$/; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
( my $method = $AUTOLOAD ) =~ s/.*:://s; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return unless $self->result and defined $self->result->{$method}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $result = $self->result->{$method}; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->{_cache}->{$method} and return $self->{_cache}->{$method}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if (ref $result eq 'HASH') { |
|
56
|
|
|
|
|
|
|
$self->{_cache}->{$method} = $self->follow_result($result); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
elsif (ref $result eq 'ARRAY') { |
|
59
|
|
|
|
|
|
|
my @results = @$result; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @response; |
|
62
|
|
|
|
|
|
|
foreach my $r (@results) { |
|
63
|
|
|
|
|
|
|
push @response, $self->follow_result($r); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
wantarray and return @response; |
|
67
|
|
|
|
|
|
|
$self->{_cache}->{$method} = \@response; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
else { |
|
70
|
|
|
|
|
|
|
$self->{_cache}->{$method} = $result; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self->{_cache}->{$method}; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub follow_result { |
|
78
|
|
|
|
|
|
|
my ($self, $result) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
if (exists $result->{'xlink:href'}) { |
|
81
|
|
|
|
|
|
|
my $href = new URI($result->{'xlink:href'}); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $action = exists $result->{action} |
|
84
|
|
|
|
|
|
|
? $result->{action} |
|
85
|
|
|
|
|
|
|
: 'GET'; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $full_href = $self->crust->response |
|
88
|
|
|
|
|
|
|
? $href->abs($self->crust->response->base) |
|
89
|
|
|
|
|
|
|
: $href; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my %args = exists $result->{args} |
|
92
|
|
|
|
|
|
|
? %{$result->{args}} |
|
93
|
|
|
|
|
|
|
: (); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $r = $self->crust->request( |
|
96
|
|
|
|
|
|
|
$action, |
|
97
|
|
|
|
|
|
|
$full_href, |
|
98
|
|
|
|
|
|
|
%args |
|
99
|
|
|
|
|
|
|
); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return $r; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
else { |
|
104
|
|
|
|
|
|
|
return new WebService::CRUST::Result($result, $self->crust); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |