lib/MojoMojo/Schema/ResultSet/Tag.pm

filter: Statementstmt 70.0% 14 / 20 Branchbran n/a Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 100% 4 / 4 totaltotal 58.9% 23 / 39 CC 3 SCAR 15.6
CC
3
Cov
56%
related_to
12.0
by_photo
2.0
BEGIN
1.0
CRAP 4.8
« lib/MojoMojo/Schema.pm ↑ Summary lib/MojoMojo/Formatter/TOC.pm »
1 package MojoMojo::Schema::ResultSet::Tag;
2  
3 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use parent qw/MojoMojo::Schema::Base::ResultSet/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 MojoMojo::Schema::ResultSet::Tag - resultset methods on tags
10  
11 =head1 METHODS
12  
13 =head2 most_used
14  
15 Returns a list of all tags and the amount each of these tags
16 is used on any page.
17  
18 =cut
19  
20 7 ▶sub most_used {
Subroutine most_used: called CC=1 SCAR=0.0
Pod documented
21 7 my ( $self, $count ) = @_;
22 7 return $self->search(
23 { page => { '!=', undef }, },
24 {
25 select => [ 'me.tag', 'count(me.tag) as refcount' ],
26 as => [ 'tag', 'refcount' ],
27 group_by => ['me.tag'],
28 order_by => ['refcount desc'],
29 }
30 );
31 }
32  
33 =head2 by_page
34  
35 Same as L</most_used> but for a particular page.
36  
37 =cut
38  
39 # TODO: Use join instead of from which is undocumented (on purpose)
40 3 ▶sub by_page {
Subroutine by_page: called CC=1 SCAR=0.0
Pod documented
41 3 my ( $self, $page ) = @_;
42 3 return $self->search(
43 {
44 'ancestor.id' => $page,
45 'me.page' => \'=descendant.id',
46 -or => [
47 -and => [
48 'descendant.lft' => \'> ancestor.lft',
49 'descendant.rgt' => \'< ancestor.rgt',
50 ],
51 'ancestor.id' => \'=descendant.id',
52 ],
53 },
54 {
55 from => 'page as ancestor, page as descendant, tag as me',
56 select => [ 'me.page', 'me.tag', 'count(me.tag) as refcount' ],
57 as => [ 'page', 'tag', 'refcount' ],
58 group_by => [ \'me.page', \'me.tag'],
59 order_by => ['refcount'],
60 }
61 );
62 }
63  
64 =head2 by_photo
65  
66 Tags on photos with counts. Used to make the tag cloud for the gallery.
67  
68 =cut
69  
70 0 ▶sub by_photo {
Subroutine by_photo: not called CC=1 SCAR=6.9
Pod documented
71 0 my ($self) = @_;
72 0 return $self->search(
73 { photo => { '!=' => undef } },
74 {
75 select => [ 'me.photo', 'me.tag', 'count(me.tag) as refcount' ],
76 as => [ 'photo', 'tag', 'refcount' ],
77 group_by => [ 'me.photo', 'me.tag'],
78 order_by => ['me.tag'],
79 }
80 );
81 }
82  
83 =head2 related_to [<tag>] [<count>]
84  
85 Returns popular tags related to this. Defaults to self.
86  
87 =cut
88  
89 0 ▶sub related_to {
Subroutine related_to: not called CC=3 SCAR=24.8
Pod documented
90 0 my ( $self, $tag, $count ) = @_;
91 0 ▶ $tag ||= $self->tag;
Condition0%0/3
$tag ||= $self->tag
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag ||= $self->tag
$tag $self->tag
Truth table0%0/3
A ||= B
A= $tagB= $self->tag
ABresult
1X1
011
000
92 0 ▶ $count ||= 10;
Condition0%0/2
$count ||= 10
l!l
00
MC/DC0%0/1
$count ||= 10
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
93 0 return $self->search(
94 {
95 'me.tag' => $tag,
96 'other.tag' => { '!=', $tag },
97 'me.page' => \'=other.page',
98 },
99 {
100 select => [ 'me.tag', 'count(me.tag) as refcount' ],
101 as => [ 'tag', 'refcount' ],
102 'group_by' => ['me.tag'],
103 'from' => 'tag me, tag other',
104 'order_by' => \'refcount',
105 'rows' => $count,
106 }
107 );
108 }
109  
110 =head1 AUTHOR
111  
112 Marcus Ramberg <mramberg@cpan.org>
113  
114 =head1 LICENSE
115  
116 This library is free software. You can redistribute it and/or modify
117 it under the same terms as Perl itself.
118  
119 =cut
120  
121 40 1;
« lib/MojoMojo/Schema.pm ↑ Summary lib/MojoMojo/Formatter/TOC.pm »