line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rest::Client::Builder; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1618
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
94
|
|
4
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
518
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
our $AUTOLOAD; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
12
|
|
|
12
|
0
|
65
|
my ($class, $opts, $path) = @_; |
11
|
|
|
|
|
|
|
|
12
|
12
|
50
|
|
|
|
108
|
return bless({ |
13
|
|
|
|
|
|
|
on_request => $opts->{on_request}, |
14
|
|
|
|
|
|
|
path => defined $path ? $path : '', |
15
|
|
|
|
|
|
|
opts => { %$opts }, |
16
|
|
|
|
|
|
|
}, $class); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _construct { |
20
|
14
|
|
|
14
|
|
19
|
my ($self, $path) = (shift, shift); |
21
|
|
|
|
|
|
|
|
22
|
14
|
|
|
|
|
15
|
my $id = $path; |
23
|
14
|
|
|
|
|
23
|
my $class = ref($self) . '::' . $path; |
24
|
|
|
|
|
|
|
|
25
|
14
|
50
|
|
|
|
47
|
if (defined $self->{path}) { |
26
|
14
|
|
|
|
|
25
|
$path = $self->{path} . '/' . $path; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
14
|
100
|
|
|
|
28
|
if (@_) { |
30
|
9
|
|
|
|
|
20
|
my $tail = '/' . join('/', @_); |
31
|
9
|
|
|
|
|
10
|
$id .= $tail; |
32
|
9
|
|
|
|
|
11
|
$path .= $tail; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
14
|
100
|
|
|
|
34
|
unless ($self->{objects}->{$id}) { |
36
|
10
|
|
|
|
|
26
|
$self->{objects}->{$id} = bless(Rest::Client::Builder->new($self->{opts}, $path), $class); |
37
|
3
|
|
|
3
|
|
21
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
469
|
|
38
|
10
|
|
|
|
|
13
|
push @{$class . '::ISA'}, 'Rest::Client::Builder'; |
|
10
|
|
|
|
|
82
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
14
|
|
|
|
|
134
|
return $self->{objects}->{$id}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub AUTOLOAD { |
45
|
7
|
|
|
7
|
|
31
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
7
|
|
|
|
|
41
|
(my $method = $AUTOLOAD) =~ s{.*::}{}; |
48
|
7
|
50
|
|
|
|
18
|
return undef if $method eq 'DESTROY'; |
49
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
743
|
|
50
|
7
|
|
|
|
|
11
|
my $ref = ref($self); |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
27
|
*{$ref . '::' . $method} = sub { |
53
|
14
|
|
|
14
|
|
2487
|
my $self = shift; |
54
|
14
|
|
|
|
|
37
|
$self->_construct($method, @_); |
55
|
7
|
|
|
|
|
25
|
}; |
56
|
|
|
|
|
|
|
|
57
|
7
|
|
|
|
|
18
|
return $self->$method(@_); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get { |
61
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
62
|
1
|
|
|
|
|
7
|
return $self->{on_request}->('GET', $self->{path}, @_); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub post { |
66
|
3
|
|
|
3
|
0
|
19
|
my $self = shift; |
67
|
3
|
|
|
|
|
20
|
return $self->{on_request}->('POST', $self->{path}, @_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub put { |
71
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
72
|
1
|
|
|
|
|
6
|
return $self->{on_request}->('PUT', $self->{path}, @_); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub delete { |
76
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
77
|
1
|
|
|
|
|
4
|
return $self->{on_request}->('DELETE', $self->{path}, @_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub patch { |
81
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
82
|
1
|
|
|
|
|
6
|
return $self->{on_request}->('PATCH', $self->{path}, @_); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub head { |
86
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
87
|
1
|
|
|
|
|
6
|
return $self->{on_request}->('HEAD', $self->{path}, @_); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |