line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package WWW::Kickstarter::Data::Categories; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
6
|
no autovivification; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
453
|
use WWW::Kickstarter::Data qw( ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
8
|
use WWW::Kickstarter::Error qw( my_croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
787
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = 'WWW::Kickstarter::Data'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _new { |
17
|
0
|
0
|
|
0
|
|
|
my_croak(400, "Incorrect usage") if @_ < 3; |
18
|
0
|
|
|
|
|
|
my ($class, $ks, $categories, %opts) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
if (my @unrecognized = keys(%opts)) { |
21
|
0
|
|
|
|
|
|
my_croak(400, "Unrecognized parameters @unrecognized"); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my @tree; |
25
|
0
|
|
|
|
|
|
for my $category (@$categories) { |
26
|
0
|
|
|
|
|
|
my $parent_info = $category->{parent}; |
27
|
0
|
0
|
|
|
|
|
my $parent_id = $parent_info ? $parent_info->{id} : 0; |
28
|
0
|
|
|
|
|
|
my $position = $category->{position}; |
29
|
0
|
|
|
|
|
|
$tree[$parent_id][$position] = $category; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
for my $category (@$categories) { |
33
|
0
|
|
|
|
|
|
my $subcategories = $tree[ $category->{id} ]; |
34
|
0
|
0
|
|
|
|
|
$category->_set_subcategories( $subcategories ? grep defined, @$subcategories : () ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $data = { |
38
|
|
|
|
|
|
|
categories => $categories, |
39
|
0
|
|
|
|
|
|
top_level => [ grep defined, @{ $tree[0] } ], |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $class->SUPER::_new($ks, $data); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
0
|
1
|
|
sub categories { @{ $_[0]{categories} } } |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub top_level_categories { @{ $_[0]{top_level} } } |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
1
|
|
sub refetch { my $self = shift; return $self->ks->categories(@_); } |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _visit { |
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $visitor = shift; |
56
|
0
|
|
|
|
|
|
my $category = shift; |
57
|
0
|
|
|
|
|
|
my $depth = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my @subcategories = |
60
|
0
|
|
|
|
|
|
sort { $a->name() cmp $b->name() } |
61
|
0
|
0
|
|
|
|
|
$category ? $category->subcategories() : @{ $self->{top_level} }; |
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $visit_next = sub { |
64
|
0
|
0
|
|
0
|
|
|
return 0 if !@subcategories; |
65
|
0
|
|
|
|
|
|
$self->_visit($visitor, shift(@subcategories), $depth+1, @_); |
66
|
0
|
|
|
|
|
|
return 1; |
67
|
0
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$visitor->($category, $depth, $visit_next, 0+@subcategories, @_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub visit { |
74
|
0
|
0
|
|
0
|
1
|
|
my_croak(400, "Incorrect usage") if @_ < 2; |
75
|
0
|
|
|
|
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $opts = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $visitor; |
79
|
0
|
0
|
|
|
|
|
if (ref($opts) eq 'CODE') { |
80
|
0
|
|
|
|
|
|
$visitor = $opts; |
81
|
0
|
|
|
|
|
|
$opts = undef; |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
|
|
|
|
$visitor = $opts->{visitor}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($opts->{root}) { |
87
|
0
|
|
|
|
|
|
$self->_visit($visitor, undef, 0, @_); |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
|
for my $category ( |
90
|
0
|
|
|
|
|
|
sort { $a->name() cmp $b->name() } |
91
|
0
|
|
|
|
|
|
@{ $self->{top_level} } |
92
|
|
|
|
|
|
|
) { |
93
|
0
|
|
|
|
|
|
$self->_visit($visitor, $category, 0, @_); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |