line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Page::FlickrLike; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
146688
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
174
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
113
|
|
5
|
4
|
|
|
4
|
|
100
|
use 5.008_001; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
144
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
3489
|
use Exporter::Lite; |
|
4
|
|
|
|
|
3110
|
|
|
4
|
|
|
|
|
26
|
|
8
|
4
|
|
|
4
|
|
986
|
use Data::Page; |
|
4
|
|
|
|
|
7357
|
|
|
4
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw( navigations ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $InnerWindow = 3; |
15
|
|
|
|
|
|
|
our $OuterWindow = 2; |
16
|
|
|
|
|
|
|
our $MinLength = 7; |
17
|
|
|
|
|
|
|
our $GlueLength = 2; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _get_min_fill { |
21
|
16
|
|
|
16
|
|
29
|
my ($page, $first_page, $last_page, $min) = @_; |
22
|
16
|
50
|
|
|
|
36
|
my $length = $last_page - $first_page + 1 < $min |
23
|
|
|
|
|
|
|
? $last_page - $first_page + 1 |
24
|
|
|
|
|
|
|
: $min; |
25
|
|
|
|
|
|
|
|
26
|
16
|
|
|
|
|
21
|
my $current_length = scalar @$page; |
27
|
16
|
|
|
|
|
31
|
return $length - $current_length; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub Data::Page::navigations { |
31
|
60
|
|
|
60
|
0
|
36341
|
my ($self, $args) = @_; |
32
|
60
|
|
|
|
|
76
|
my $nav; |
33
|
60
|
|
|
|
|
80
|
my $prev_skip = 1; |
34
|
60
|
|
|
|
|
72
|
my $next_skip = 1; |
35
|
|
|
|
|
|
|
|
36
|
60
|
50
|
|
|
|
146
|
my $inner = exists $args->{inner_window} |
37
|
|
|
|
|
|
|
? $args->{inner_window} |
38
|
|
|
|
|
|
|
: $Data::Page::FlickrLike::InnerWindow; |
39
|
60
|
50
|
|
|
|
123
|
my $outer = exists $args->{outer_window} |
40
|
|
|
|
|
|
|
? $args->{outer_window} |
41
|
|
|
|
|
|
|
: $Data::Page::FlickrLike::OuterWindow; |
42
|
60
|
50
|
|
|
|
105
|
my $min = exists $args->{min_length} |
43
|
|
|
|
|
|
|
? $args->{min_length} |
44
|
|
|
|
|
|
|
: $Data::Page::FlickrLike::MinLength; |
45
|
60
|
50
|
|
|
|
115
|
my $glue_length = exists $args->{glue_length} |
46
|
|
|
|
|
|
|
? $args->{glue_length} |
47
|
|
|
|
|
|
|
: $Data::Page::FlickrLike::GlueLength; |
48
|
|
|
|
|
|
|
|
49
|
60
|
|
|
|
|
138
|
my $current_page = $self->current_page; |
50
|
60
|
|
|
|
|
2804
|
my $last_page = $self->last_page; |
51
|
60
|
|
|
|
|
1317
|
my $first_page = $self->first_page; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## build the pages around current_page to begin with |
54
|
60
|
|
|
|
|
315
|
for (my $i = $current_page - $inner; $i <= $current_page + $inner ; $i++) { |
55
|
420
|
100
|
100
|
|
|
1977
|
push @$nav, $i if $i >= $first_page && $i <= $last_page; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
## shortcut if we already take all the room |
59
|
60
|
100
|
100
|
|
|
236
|
if ($nav->[0] == $first_page && $nav->[-1] == $last_page) { |
60
|
10
|
50
|
|
|
|
57
|
return wantarray ? @$nav : $nav; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
## NOTE: there are some extra operations in there just in case $first_page != 1 |
64
|
|
|
|
|
|
|
## but, this shouldn't really be necessary... |
65
|
|
|
|
|
|
|
|
66
|
50
|
100
|
66
|
|
|
297
|
if ($nav->[0] == $first_page && $nav->[-1] != $last_page) { |
|
|
100
|
66
|
|
|
|
|
67
|
|
|
|
|
|
|
## we're stuck at the beginning, check for $min_lengh |
68
|
4
|
|
|
|
|
13
|
my $min_fill = _get_min_fill($nav, $first_page, $last_page, $min); |
69
|
4
|
|
|
|
|
6
|
my $last = $nav->[-1]; |
70
|
4
|
|
|
|
|
10
|
push @$nav, map { $last + $_ } (1 .. $min_fill); |
|
4
|
|
|
|
|
11
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
## stuck at the end: fill the beginning using $min_length |
74
|
|
|
|
|
|
|
elsif ($nav->[0] != $first_page && $nav->[-1] == $last_page) { |
75
|
12
|
|
|
|
|
29
|
my $min_fill = _get_min_fill($nav, $first_page, $last_page, $min); |
76
|
12
|
|
|
|
|
19
|
my $first = $nav->[0]; |
77
|
12
|
|
|
|
|
28
|
unshift @$nav, reverse map { $first - $_ } (1 .. $min_fill); |
|
24
|
|
|
|
|
53
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
## now, care about extremities specifically |
81
|
50
|
|
|
|
|
58
|
my (@begin, @end); |
82
|
50
|
|
|
|
|
98
|
for (0 .. ($outer - 1)) { |
83
|
100
|
|
|
|
|
147
|
push @begin, $first_page + $_; |
84
|
100
|
|
|
|
|
166
|
push @end, $last_page - $_; |
85
|
|
|
|
|
|
|
} |
86
|
50
|
|
|
|
|
66
|
@end = reverse @end; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
## we might need some glue |
89
|
50
|
100
|
|
|
|
117
|
if ($begin[-1] < $nav->[0] - 1) { |
90
|
42
|
|
|
|
|
60
|
my $to_glue = $nav->[0] - $begin[-1] - 1; |
91
|
42
|
100
|
|
|
|
69
|
if ($to_glue <= $glue_length) { |
92
|
|
|
|
|
|
|
## we can glue! |
93
|
4
|
|
|
|
|
5
|
my $last = $begin[-1]; |
94
|
4
|
|
|
|
|
11
|
push @begin, map { $last + $_ } (1 .. $to_glue); |
|
6
|
|
|
|
|
15
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
38
|
|
|
|
|
52
|
push @begin, 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
50
|
100
|
|
|
|
139
|
if ($end[0] > $nav->[-1] + 1) { |
102
|
34
|
|
|
|
|
44
|
my $to_glue = $end[0] - $nav->[-1] - 1; |
103
|
34
|
100
|
|
|
|
50
|
if ($to_glue <= $glue_length) { |
104
|
|
|
|
|
|
|
## we can glue! |
105
|
4
|
|
|
|
|
6
|
my $first = $end[0]; |
106
|
4
|
|
|
|
|
12
|
unshift @end, reverse map { $first - $_ } (1 .. $to_glue); |
|
6
|
|
|
|
|
15
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
30
|
|
|
|
|
72
|
unshift @end, 0; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
## trim redundant items if they exist |
114
|
50
|
|
100
|
|
|
243
|
while (@begin && $begin[-1] >= $nav->[0]) { |
115
|
10
|
|
|
|
|
36
|
pop @begin; |
116
|
|
|
|
|
|
|
}; |
117
|
50
|
|
66
|
|
|
225
|
while (@end && $end[0] && $end[0] <= $nav->[-1]) { |
|
|
|
100
|
|
|
|
|
118
|
26
|
|
|
|
|
104
|
shift @end; |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
|
121
|
50
|
|
|
|
|
198
|
$nav = [ @begin, @$nav, @end ]; |
122
|
|
|
|
|
|
|
|
123
|
50
|
50
|
|
|
|
289
|
return wantarray ? @$nav : $nav; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
127
|
|
|
|
|
|
|
__END__ |