line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Socialtext::Resting::TaggedPages; |
2
|
1
|
|
|
1
|
|
2168
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Exporter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
887
|
|
5
|
|
|
|
|
|
|
our @EXPORT_OK = qw/tagged_pages/; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Socialtext::Resting::TaggedPages - Utilities for finding pages with tags |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Socialtext::Resting::TaggedPages qw/tagged_pages/; |
14
|
|
|
|
|
|
|
my $untagged_pages = tagged_pages( rester => $r, notags => 1 ); |
15
|
|
|
|
|
|
|
my $foo_pages = tagged_pages( rester => $r, tags => ['foo'] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 FUNCTIONS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 tagged_pages |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Return a list of tagged pages. See SYNOPSIS for usage. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub tagged_pages { |
30
|
3
|
|
|
3
|
1
|
1794
|
my %opts = ( |
31
|
|
|
|
|
|
|
tags => [], |
32
|
|
|
|
|
|
|
notags => undef, |
33
|
|
|
|
|
|
|
@_, |
34
|
|
|
|
|
|
|
); |
35
|
3
|
50
|
|
|
|
13
|
my $r = $opts{rester} or die "Rester is mandatory"; |
36
|
|
|
|
|
|
|
|
37
|
3
|
|
|
|
|
12
|
$r->accept('perl_hash'); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
11
|
my $all_pages = $r->get_pages; |
40
|
3
|
|
|
|
|
6
|
my @pages; |
41
|
3
|
|
|
|
|
7
|
for my $p (@$all_pages) { |
42
|
9
|
|
50
|
|
|
22
|
my $pagetags = $p->{tags} || []; |
43
|
9
|
100
|
|
|
|
18
|
if ($opts{notags}) { |
44
|
3
|
100
|
|
|
|
12
|
next if @$pagetags; |
45
|
1
|
|
|
|
|
3
|
push @pages, $p->{page_id}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
6
|
|
|
|
|
8
|
my $missing_tag = 0; |
49
|
6
|
|
|
|
|
8
|
for my $t (@{ $opts{tags} }) { |
|
6
|
|
|
|
|
12
|
|
50
|
9
|
100
|
|
|
|
19
|
unless (grep { $_ eq $t } @$pagetags) { |
|
9
|
|
|
|
|
33
|
|
51
|
4
|
|
|
|
|
9
|
$missing_tag++; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
6
|
100
|
|
|
|
24
|
push @pages, $p->{page_id} unless $missing_tag; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
3
|
|
|
|
|
15
|
return \@pages; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 AUTHOR |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Luke Closs, C<< >> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 LICENSE |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
67
|
|
|
|
|
|
|
under the same terms as Perl itself. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |