Rubric/EntryTag.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 78.5% 11 / 14 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 78.2% 61 / 78 CC 10 SCAR 13.4
CC
10
Cov
79%
related_tags
6.8
related_tags_counted
5.0
_nullify_values
3.0
CRAP 3.8
« Rubric/WebApp/Login.pm ↑ Summary Rubric/Entry/Formatter.pm »
1 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Rubric::EntryTag 0.157;
4 # ABSTRACT: a tag on an entry
5  
6 12 ▶use String::TagString;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 DESCRIPTION
9 #pod
10 #pod This class provides an interface to tags on Rubric entries. It inherits from
11 #pod Rubric::DBI, which is a Class::DBI class.
12 #pod
13 #pod =cut
14  
15 12 ▶use base qw(Rubric::DBI);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 12 __PACKAGE__->table('entrytags');
18  
19 #pod =head1 COLUMNS
20 #pod
21 #pod id - a unique identifier
22 #pod entry - the tagged entry
23 #pod tag - the tag itself
24 #pod tag_value - the value of the tag (for tags in "tag:value" form)
25 #pod
26 #pod =cut
27  
28 12 __PACKAGE__->columns(All => qw(id entry tag tag_value));
29  
30 #pod =head1 RELATIONSHIPS
31 #pod
32 #pod =head2 entry
33 #pod
34 #pod The entry attribute returns a Rubric::Entry.
35 #pod
36 #pod =cut
37  
38 12 __PACKAGE__->has_a(entry => 'Rubric::Entry');
39  
40 #pod =head1 TRIGGERS
41 #pod
42 #pod =cut
43  
44 12 __PACKAGE__->add_trigger(before_create => \&_nullify_values);
45 12 __PACKAGE__->add_trigger(before_update => \&_nullify_values);
46  
47 18 ▶sub _nullify_values {
Subroutine _nullify_values: called CC=3 SCAR=11.1
48 18 my $self = shift;
49 $self->tag_value(undef)
50 18 ▶ unless defined $self->{tag_value} and length $self->{tag_value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tag_value"} and length $self->{"tag_value"} 17 1 18
Condition66%2/3
defined $self->{"tag_value"} and length $self->{"tag_value"}
!ll&&!rl&&r
1701
MC/DC50%1/2
defined $self->{"tag_value"} and length $self->{"tag_value"}
defined $self->{"tag_value"} length $self->{"tag_value"}
Truth table66%2/3
A and B
A= defined $self->{"tag_value"}B= length $self->{"tag_value"}
ABresult
0X0
100
111
51 }
52  
53 #pod =head1 METHODS
54 #pod
55 #pod =head2 related_tags(\@tags)
56 #pod
57 #pod This method returns a reference to an array of tags related to all the given
58 #pod tags. Tags are related if they occur together on entries.
59 #pod
60 #pod =cut
61  
62 1 ▶sub related_tags {
Subroutine related_tags: called CC=4 SCAR=19.2
Pod documented
63 1 my ($self, $tags) = @_;
64 1 ▶ return unless $tags and my @tags = @$tags;
Branch: 1 branch
BranchTrueFalseTotal
unless $tags and my(@tags) = @$tags 0 1 1
Condition33%1/3
$tags and my(@tags) = @$tags
!ll&&!rl&&r
001
MC/DC0%0/2
$tags and my(@tags) = @$tags
$tags my(@tags) = @$tags
Truth table33%1/3
A and B
A= $tagsB= my(@tags) = @$tags
ABresult
0X0
100
111
65  
66 # or maybe we should throw an exception? -- rjbs, 2006-02-13
67 1 ▶ return [] if grep { $_ eq '@private' } @tags;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "\@private";} @tags 1 0 1
68  
69 my $query = q|
70 SELECT DISTINCT tag FROM entrytags
71 WHERE
72 0 tag NOT IN (| . join(',',map { $self->db_Main->quote($_) } @tags) . q|)
73 AND tag NOT LIKE '@%'
74 AND | .
75 join ' AND ',
76 0 map { "entry IN (SELECT entry FROM entrytags WHERE tag=$_)" }
77 0 map { $self->db_Main->quote($_) }
78 @tags;
79  
80 0 $self->db_Main->selectcol_arrayref($query, undef);
81 }
82  
83 #pod =head3 related_tags_counted(\@tags)
84 #pod
85 #pod This is the obvious conjunction of C<related_tags> and C<tags_counted>. It
86 #pod returns an arrayref of arrayrefs, each a pair of tag/occurance values.
87 #pod
88 #pod =cut
89  
90 23 ▶sub related_tags_counted {
Subroutine related_tags_counted: called CC=5 SCAR=16.1
Pod documented
91 23 my ($self, $tags) = @_;
92 23 ▶ return unless $tags;
Branch: 1 branch
BranchTrueFalseTotal
unless $tags 10 13 23
93 13 ▶ $tags = [ keys %$tags ] if ref $tags eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $tags eq "HASH" 12 1 13
94 13 ▶ return unless my @tags = @$tags;
Branch: 1 branch
BranchTrueFalseTotal
unless my(@tags) = @$tags 0 13 13
95  
96 # or maybe we should throw an exception? -- rjbs, 2006-02-13
97 13 ▶ return [] if grep { $_ eq '@private' } @tags;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq "\@private";} @tags 1 12 13
98  
99 my $query = q|
100 SELECT DISTINCT tag, COUNT(*) AS count
101 FROM entrytags
102 WHERE tag NOT IN (|
103 12 . join(',',map { $self->db_Main->quote($_) } @tags) . q|)
104 AND tag NOT LIKE '@%'
105 AND | .
106 join ' AND ',
107 12 map { "entry IN (SELECT entry FROM entrytags WHERE tag=$_)" }
108 12 map { $self->db_Main->quote($_) }
109 @tags;
110  
111 12 $query .= " GROUP BY tag";
112  
113 12 $self->db_Main->selectall_arrayref($query, undef);
114 }
115  
116 #pod =head2 stringify_self
117 #pod
118 #pod =cut
119  
120 0 ▶sub stringify_self {
Subroutine stringify_self: not called CC=1 SCAR=6.9
Pod documented
121 0 my ($self) = @_;
122 0 String::TagString->string_from_tags({
123 $self->tag => $self->tag_value
124 });
125 }
126  
127 12 1;
128  
129 __END__
« Rubric/WebApp/Login.pm ↑ Summary Rubric/Entry/Formatter.pm »