line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::Roles::Permissions; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2982
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
4
|
1
|
|
|
1
|
|
545
|
use Flickr::Types::Tools qw ( FlickrPermStr ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
525
|
use Types::Standard qw( Bool); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
634
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
1596
|
use Moo::Role; |
|
1
|
|
|
|
|
33313
|
|
|
1
|
|
|
|
|
29
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.21_03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _permissions => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
isa => FlickrPermStr, |
14
|
|
|
|
|
|
|
builder => '_get_permissions', |
15
|
|
|
|
|
|
|
clearer => 1, |
16
|
|
|
|
|
|
|
predicate => 1, |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
default => 'none', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _api_connects => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => Bool, |
24
|
|
|
|
|
|
|
required => 1, |
25
|
|
|
|
|
|
|
clearer => 1, |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
builder => '_can_connect', |
28
|
|
|
|
|
|
|
default => 0, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
requires qw( _build_api api user); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub connects { |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
return $self->_api_connects if $self->_api_connects; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->_can_connect; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self->_api_connects; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub permissions { |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
return $self->_permissions if $self->_has_permissions; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->_get_permissions; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return $self->_permissions; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _get_permissions { |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
0
|
|
|
|
unless ( $self->has_token and $self->has_token_secret ) { |
58
|
0
|
|
|
|
|
|
carp |
59
|
|
|
|
|
|
|
'Tool needs to have an access token and token_secret to obtain permission'; |
60
|
0
|
|
|
|
|
|
$self->_clear_permissions; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $temp = $self->api; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $rsp = $temp->execute_method('flickr.auth.oauth.checkToken'); |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ( $rsp->success == 0 ) { |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->_permissions('none'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $answer = $rsp->as_hash; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$self->_permissions( $answer->{oauth}->{perms} ); |
77
|
0
|
|
|
|
|
|
$self->_user( $answer->{oauth}->{user} ); |
78
|
0
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _can_connect { |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $temp = $self->api; |
85
|
0
|
|
|
|
|
|
my $rsp = |
86
|
|
|
|
|
|
|
$temp->execute_method( 'flickr.test.echo', { 'tool' => 'can_connect' } ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->{_api_connects} = 0; |
89
|
0
|
|
|
|
|
|
$self->_clear_permissions; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
unless ( $rsp->rc eq '200' ) { |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
carp "\nConnect attempt to Flickr received " |
94
|
|
|
|
|
|
|
. $rsp->rc |
95
|
|
|
|
|
|
|
. " html response code\n"; |
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
unless ( $rsp->success eq '1' ) { |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
carp "\nConnection was made but received a " |
103
|
|
|
|
|
|
|
. $rsp->error_code |
104
|
|
|
|
|
|
|
. "\n " |
105
|
|
|
|
|
|
|
. $rsp->error_message . "\n"; |
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $answer = $rsp->as_hash; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ( $answer->{'tool'} eq 'can_connect' ) { |
113
|
0
|
|
|
|
|
|
$self->{_api_connects} = 1; |
114
|
0
|
|
|
|
|
|
return; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
carp "\nUnexpected data received back from Flickr\n"; |
120
|
0
|
|
|
|
|
|
return; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
1
|
|
1638
|
no Moo::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |