line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Snoo::Subreddit; |
2
|
5
|
|
|
5
|
|
140145
|
use Moo; |
|
5
|
|
|
|
|
40801
|
|
|
5
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
extends 'Mojo::Snoo::Base'; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
5948
|
use Mojo::Collection; |
|
5
|
|
|
|
|
8356
|
|
|
5
|
|
|
|
|
161
|
|
7
|
5
|
|
|
5
|
|
1656
|
use Mojo::Snoo::Link; |
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
215
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
40
|
use constant FIELD => 'name'; |
|
5
|
|
|
|
|
60
|
|
|
5
|
|
|
|
|
3391
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has name => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => sub { |
14
|
|
|
|
|
|
|
die "Subreddit needs a name!" unless $_[0]; |
15
|
|
|
|
|
|
|
}, |
16
|
|
|
|
|
|
|
required => 1 |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
5
|
100
|
|
5
|
0
|
9074
|
sub BUILDARGS { shift->SUPER::BUILDARGS(@_ == 1 ? (name => shift) : @_) } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub mods { |
22
|
1
|
|
|
1
|
1
|
13
|
my $self = shift; |
23
|
1
|
|
|
|
|
5
|
my $path = '/r/' . $self->name . '/about/moderators'; |
24
|
1
|
|
|
|
|
6
|
my $res = $self->_do_request('GET', $path); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Do we have a callback? |
27
|
1
|
50
|
|
|
|
999
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
28
|
1
|
50
|
|
|
|
5
|
$res->$cb if $cb; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
372
|
my @mods = @{$res->json->{data}{children}}; |
|
1
|
|
|
|
|
8
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# FIXME should we return User objects instead? or combined? |
33
|
1
|
|
|
|
|
356
|
my @collection; |
34
|
1
|
|
|
|
|
2
|
for my $child (@mods) { |
35
|
2
|
|
|
|
|
10
|
my $pkg = 'Mojo::Snoo::Subreddit::Mods::' . $self->name . '::' . $child->{name}; |
36
|
2
|
|
|
|
|
10
|
push @collection, $self->_monkey_patch($pkg, $child); |
37
|
|
|
|
|
|
|
} |
38
|
1
|
|
|
|
|
6
|
Mojo::Collection->new(@collection); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub about { |
42
|
1
|
|
|
1
|
1
|
17
|
my $self = shift; |
43
|
1
|
|
|
|
|
6
|
my $path = '/r/' . $self->name . '/about'; |
44
|
1
|
|
|
|
|
6
|
my $res = $self->_do_request('GET', $path); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Do we have a callback? |
47
|
1
|
50
|
|
|
|
838
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
48
|
1
|
50
|
|
|
|
4
|
$res->$cb if $cb; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
591
|
my $pkg = 'Mojo::Snoo::Subreddit::About::' . $self->name; |
51
|
1
|
|
|
|
|
8
|
$self->_monkey_patch($pkg, $res->json->{data}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _get_links { |
55
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
6
|
my $path = '/r/' . $self->name; |
58
|
|
|
|
|
|
|
|
59
|
1
|
50
|
|
|
|
3
|
if (my $sort = shift) { |
60
|
0
|
|
|
|
|
0
|
$path .= "/$sort"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Do we have a callback? |
64
|
1
|
50
|
|
|
|
3
|
my $cb = ref $_[-1] eq 'CODE' ? pop : undef; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Did we receive extra endpoint parameters? |
67
|
1
|
50
|
|
|
|
2
|
my $params = ref $_[-1] eq 'HASH' ? pop : {}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Define these from special method calls unless |
70
|
|
|
|
|
|
|
# user has already done so via the params hash |
71
|
1
|
|
0
|
|
|
3
|
$params->{t} ||= shift || ''; |
|
|
|
33
|
|
|
|
|
72
|
1
|
|
50
|
|
|
9
|
$params->{limit} ||= shift || ''; |
|
|
|
33
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
8
|
my $res = $self->_do_request('GET', $path, %$params); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# run callback |
77
|
1
|
50
|
|
|
|
1307
|
$res->$cb if $cb; |
78
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
391
|
my @children = |
80
|
1
|
|
|
|
|
13
|
map { $_->{kind} eq 't3' ? $_->{data} : () } # |
81
|
1
|
|
|
|
|
378
|
@{$res->json->{data}{children}}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
2
|
my %args = map { $_ => $self->$_ } ( |
|
4
|
|
|
|
|
21
|
|
84
|
|
|
|
|
|
|
qw( |
85
|
|
|
|
|
|
|
username |
86
|
|
|
|
|
|
|
password |
87
|
|
|
|
|
|
|
client_id |
88
|
|
|
|
|
|
|
client_secret |
89
|
|
|
|
|
|
|
) |
90
|
|
|
|
|
|
|
); |
91
|
1
|
|
|
|
|
2
|
Mojo::Collection->new(map { Mojo::Snoo::Link->new(%args, %$_) } @children); |
|
2
|
|
|
|
|
228
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
1
|
1
|
15
|
sub links { shift->_get_links('' , '' , @_) } |
95
|
0
|
|
|
0
|
1
|
|
sub links_new { shift->_get_links('new' , '' , @_) } |
96
|
0
|
|
|
0
|
1
|
|
sub links_rising { shift->_get_links('rising' , '' , @_) } |
97
|
0
|
|
|
0
|
1
|
|
sub links_contro { shift->_get_links('controversial', '' , @_) } |
98
|
0
|
|
|
0
|
1
|
|
sub links_contro_week { shift->_get_links('controversial', 'week' , @_) } |
99
|
0
|
|
|
0
|
1
|
|
sub links_contro_month { shift->_get_links('controversial', 'month', @_) } |
100
|
0
|
|
|
0
|
1
|
|
sub links_contro_year { shift->_get_links('controversial', 'year' , @_) } |
101
|
0
|
|
|
0
|
1
|
|
sub links_contro_all { shift->_get_links('controversial', 'all' , @_) } |
102
|
0
|
|
|
0
|
1
|
|
sub links_top { shift->_get_links('top' , '' , @_) } |
103
|
0
|
|
|
0
|
1
|
|
sub links_top_week { shift->_get_links('top' , 'week' , @_) } |
104
|
0
|
|
|
0
|
1
|
|
sub links_top_month { shift->_get_links('top' , 'month', @_) } |
105
|
0
|
|
|
0
|
1
|
|
sub links_top_year { shift->_get_links('top' , 'year' , @_) } |
106
|
0
|
|
|
0
|
1
|
|
sub links_top_all { shift->_get_links('top' , 'all' , @_) } |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |