Tags.pm

filter: Statementstmt 4.0% 4 / 99 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 6.6% 1 / 15 Podpod 0.0% 0 / 11 totaltotal 3.6% 5 / 137 CC 12 SCAR 19.4
CC
12
Cov
4%
obj_to_otl
12.0
listtags
12.0
get_tags_compact
12.0
CRAP 7.0
« Basic.pm ↑ Summary
1 #!/usr/bin/perl
2 package Fry::Lib::CDBI::Tags;
3 1 ▶use strict qw/vars refs/; #?forget the subs cause makes hash assignment a pain
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 #variables
6 1 our $tagcolumn='tags';
7 #our cdbi_search = "search_abstract";
8 #functions
9 0 ▶ sub _default_data {
Subroutine _default_data: not called CC=1 SCAR=6.9
10 return {
11 0 depend=>[qw/:CDBI::Basic/],
12 vars=>{ otlnum=>'3',tag_delimiter=>',' },
13 cmds=>{tagcount=>{qw/a tc aa aliasInputAndSql/},
14 tagname=>{qw/a tn aa aliasInputAndSql/},
15 auto_outline=>{qw/a ao/},#aa aliasInputAndSql/},
16 sorted_tag_list=>{qw/a ts aa aliasInputAndSql/},
17 tagcount_obj=>{qw/a :tc/},
18 tagname_obj=>{qw/a :tn/},
19 },
20 opts=>{otlnum=>{qw/a otl type var noreset 1 default 3/ }}
21 # subs=>{qw/g init_tag_group/ }
22 }
23 }
24  
25 #shell commands
26 0 ▶ sub auto_outline {
Subroutine auto_outline: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my $class = shift;
28  
29 0 $class->lib->requireLibraries(':CDBI::Outline');
30 0 my @a = $class->aliasInputAndSql(@_);
31 0 my @results = $class->${\$class->Var('cdbi_search')}(@a);
32 0 $class->obj_to_otl(\@_,\@results);
33 }
34 0 ▶ sub tagcount {
Subroutine tagcount: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my $cls = shift;
36  
37 0 my @results = $cls->${\$cls->Var('cdbi_search')}(@_);
38 0 ▶ if (@results > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@results > 0) { } 0 0 0
39 0 $cls->tagcount_obj(@results)
40 }
41 0 else { $cls->view("No search results\n") }
42 }
43 0 ▶ sub tagname {
Subroutine tagname: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my $cls = shift;
45 0 my @results = $cls->${\$cls->Var('cdbi_search')}(@_);
46 0 ▶ if (@results > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@results > 0) { } 0 0 0
47 0 $cls->tagname_obj(@results)
48 }
49 0 else { $cls->view("No search results\n") }
50 }
51 0 ▶ sub tagcount_obj {
Subroutine tagcount_obj: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my ($cls,@obj) = @_;
53 0 my $tags = $cls->get_tags_compact(@obj);
54 0 $cls->print_tags_compact($tags);
55 }
56 0 ▶ sub tagname_obj {
Subroutine tagname_obj: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my ($cls,@obj) = @_;
58 0 my @sortedtags = $cls->listtags(@obj);
59 0 $cls->print_tags(@sortedtags);
60 }
61 0 ▶ sub sorted_tag_list {
Subroutine sorted_tag_list: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my $class = shift;
63 0 my @results = $class->${\$class->Var('cdbi_search')}(@_);
64 0 return sort $class->_unique_result_tags(@results);
65 }
66 #internal methods
67 0 ▶ sub obj_to_otl {
Subroutine obj_to_otl: not called CC=3 SCAR=24.8
Pod undocumented
68 0 my $class = shift;
69 0 my @aliasedinput= @{shift()};
70 0 my @results = @{shift()};
71  
72 #gives unique tags but in order of most tags
73 0 my @tagnames = map { $_->{name} } $class->listtags(@results);
74 0 ▶ if (@tagnames == 0) { $class->view("no taggnames,outline not possible\n"); return}
Branch: 1 branch
BranchTrueFalseTotal
if (@tagnames == 0) 0 0 0
75  
76 #delete first tagname since it's a repeat of parent tag
77 0 ▶ shift @tagnames if ("@aliasedinput" =~ /$tagcolumn/);
Branch: 1 branch
BranchTrueFalseTotal
if join($", @aliasedinput) =~ /$Fry::Lib::CDBI::Tags::tagcolumn/ 0 0 0
78  
79 #create autoquery
80 0 my @savedtags = splice(@tagnames,0,$class->Var('otlnum'));
81 0 my $input = "@aliasedinput"."(".join(',',@savedtags).")";
82 #print "i: $input:\n";
83  
84 0 $class->view($class->outlineSearches($input));
85 }
86 0 ▶ sub _all_result_tags {
Subroutine _all_result_tags: not called CC=1 SCAR=6.9
87 0 my ($class,@cdbi) = @_;
88 0 my @tcolumn = map {$_->$tagcolumn} @cdbi;
89 0 return map {split(/${\$class->Var('tag_delimiter')}/,$_) } @tcolumn;
90 }
91 0 ▶ sub _unique_result_tags {
Subroutine _unique_result_tags: not called CC=2 SCAR=17.9
92 0 my ($class,@cdbi) = @_;
93 0 my @tags = $class->_all_result_tags(@cdbi);
94 0 my %uniq;
95 0 for (@tags) { $uniq{$_}++ }
96 0 return keys %uniq;
97 }
98 0 ▶ sub listtags {
Subroutine listtags: not called CC=3 SCAR=24.8
Pod undocumented
99 #d:returns tags and number of occurences in table
100 0 my ($class,@cdbi) = @_;
101 0 my @tags = $class->_all_result_tags(@cdbi);
102 0 my (%uniqtag,$result);
103  
104 #count + get unique tags
105 0 for (@tags) { $uniqtag{$_}{count}++; }
106  
107 #combine count + tagname into @ of %
108 0 @tags=();
109 0 for (keys %uniqtag) {
110 0 push(@tags,{name=>$_,count=>$uniqtag{$_}{count}});
111 }
112
113 #sort descending
114 0 my @sortedtags = sort {${$b}{count} <=> ${$a}{count}} @tags;
115 0 return @sortedtags;
116 }
117 0 ▶ sub get_tags_compact {
Subroutine get_tags_compact: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my $class = shift;
119 0 my @sortedtags = $class->listtags(@_);
120 0 my ($i,$j,@body);
121  
122 0 ▶ while ($i != @sortedtags -1){
Branch: 1 branch
BranchTrueFalseTotal
if ($i != @sortedtags - 1) 0 0 0
123 0 my $previouscount;
124  
125 #print $sortedtags[$i]{count},": ";
126 0 $body[$j]{count} = $sortedtags[$i]{count};
127 #print $sortedtags[$i]{name},$class->Var('delim')->{tag};
128 0 $body[$j]{tags} .= $sortedtags[$i]{name}. $class->Var('tag_delimiter');
129  
130 0 $previouscount = $sortedtags[$i]{count};
131 0 $i++;
132  
133 #create taggroup
134 0 my @taggroup;
135 #prints groups of tags with same count
136 0 ▶ while ($sortedtags[$i]{count} == $previouscount) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sortedtags[$i]{"count"} == $previouscount) 0 0 0
137 #print $sortedtags[$i]{name},$class->Var('delim')->{tag};
138 0 push(@taggroup,$sortedtags[$i]{name});
139 0 $previouscount = $sortedtags[$i]{count};
140 0 $i++;
141 }
142  
143 0 $body[$j]{tags} .= join($class->Var('tag_delimiter'),@taggroup);
144 0 $j++;
145 }
146 0 return \@body;
147 }
148 #format fns
149 0 ▶ sub print_tags_compact {
Subroutine print_tags_compact: not called CC=2 SCAR=17.9
Pod undocumented
150 0 my ($cls,$tags) = @_;
151 0 my $output;
152  
153 0 for (@$tags) {
154 0 $output .= $_->{count}.": ".$_->{tags}."\n";
155 }
156 0 $cls->view($output);
157 }
158 0 ▶ sub print_tags {
Subroutine print_tags: not called CC=2 SCAR=17.9
Pod undocumented
159 0 my ($class,@sortedtags) = @_;
160 0 my $result;
161 0 for (@sortedtags) { $result .= "$_->{count}: $_->{name}\n";}
162 0 $class->view($result);
163 }
164  
165  
166 __END__
« Basic.pm ↑ Summary