UserSearch.pm

filter: Statementstmt 11.4% 22 / 192 Branchbran 0.0% 0 / 100 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 17.1% 6 / 35 Podpod 27.7% 5 / 18 totaltotal 7.0% 33 / 467 CC 82 SCAR 50.2
CC
82
Cov
6%
compare
342.0
writeups
306.0
sort_results
306.0
CRAP 151.4
« Interface.pm ↑ Summary Writeup.pm »
1 # E2::UserSearch
2 # Jose M. Weeks <jose@joseweeks.com>
3 # 06 July 2003
4 #
5 # See bottom for pod documentation.
6  
7 package E2::UserSearch;
8  
9 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use E2::Ticker;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use E2::Writeup;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = "0.33";
18 1 our @ISA = qw(E2::Ticker);
19 1 our $DEBUG; *DEBUG = *E2::Interface::DEBUG;
20  
21 sub new;
22 sub clear;
23  
24 sub writeups;
25 sub sort_results;
26  
27 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
28 0 my $arg = shift;
29 0 ▶ my $class = ref( $arg ) || $arg;
Condition0%0/3
ref $arg || $arg
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $arg || $arg
ref $arg $arg
Truth table0%0/3
A || B
A= ref $argB= $arg
ABresult
1X1
011
000
30 0 my $self = $class->SUPER::new();
31  
32 0 bless ($self, $class);
33  
34 0 $self->clear;
35  
36 0 return $self;
37 }
38  
39 0 ▶sub clear {
Subroutine clear: not called CC=3 SCAR=24.8
Pod undocumented
40 0 ▶ my $self = shift or croak "Usage: clear E2USERSEARCH";
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Usage: clear E2USERSEARCH") 0 0 0
41  
42 0 ▶ warn "E2::UserSearch::clear\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG > 1 0 0 0
43  
44 0 $self->{lastuser} = undef; # username of last user searched
45 0 @{ $self->{writeups} } = (); # list of E2::Writeup
46  
47 0 return 1;
48 }
49  
50 0 ▶sub writeups {
Subroutine writeups: not called CC=17 SCAR=57.2
Pod documented
51 0 ▶ my $self = shift or croak "Usage: writeups E2USERSEARCH [ USER ] [, SORT_BY ] [, COUNT ] [, STARTAT ]";
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Usage: writeups E2USERSEARCH [ USER ] [, SORT_BY ] [, COUNT ] [, STARTAT ]") 0 0 0
52 0 ▶ my $user = shift || $self->this_username;
Condition0%0/3
shift() || $self->this_username
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->this_username
shift() $self->this_username
Truth table0%0/3
A || B
A= shift()B= $self->this_username
ABresult
1X1
011
000
53 0 my $sort_by = shift;
54 0 my $count = shift;
55 0 my $startat = shift;
56  
57 0 ▶ warn "E2::UserSearch::writeups\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG > 1 0 0 0
58
59 0 ▶ if( !$user ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 0 0
60 0 ▶ warn "No user specified and not logged in" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG 0 0 0
61 0 return undef;
62 }
63  
64 0 my %opt;
65  
66 0 $opt{searchuser} = $user;
67 0 ▶ $opt{startat} = $startat if $startat;
Branch: 1 branch
BranchTrueFalseTotal
if $startat 0 0 0
68  
69 0 ▶ if( $sort_by ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sort_by) { } 0 0 0
70 0 $sort_by = lc($sort_by);
71 0 ▶ if( $sort_by ne 'rep' && $sort_by ne 'creation' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($sort_by ne "rep" and $sort_by ne "creation" and $sort_by ne "title") 0 0 0
Condition0%0/6
$sort_by ne "rep" and $sort_by ne "creation" and $sort_by ne "title"
!ll&&!rl&&r
000
$sort_by ne "rep" and $sort_by ne "creation"
!ll&&!rl&&r
000
MC/DC0%0/3
$sort_by ne "rep" and $sort_by ne "creation" and $sort_by ne "title"
$sort_by ne "rep" $sort_by ne "creation" $sort_by ne "title"
Truth table0%0/4
A and B and C
A= $sort_by ne "rep"B= $sort_by ne "creation"C= $sort_by ne "title"
ABCresult
0XX0
10X0
1100
1111
72 $sort_by ne 'title' ) {
73 0 croak "Invalid search option: $sort_by";
74 }
75  
76 0 $opt{sort} = $sort_by;
77 } else {
78 0 $opt{nosort} = 1;
79 0 $sort_by = "none";
80 }
81  
82 0 ▶ if( $count && $count == -1 ) { # Get all
Branch: 2 branches
BranchTrueFalseTotal
if ($count and $count == -1) { } 0 0 0
elsif ($count) { } 0 0 0
Condition0%0/3
$count and $count == -1
!ll&&!rl&&r
000
MC/DC0%0/2
$count and $count == -1
$count $count == -1
Truth table0%0/3
A and B
A= $countB= $count == -1
ABresult
0X0
100
111
83 0 $opt{nolimit} = 1;
84 } elsif( $count ) {
85 0 $opt{count} = $count;
86 }
87  
88 0 $user = lc( $user );
89  
90 # We don't add this search to the last if this is a
91 # search on a new user.
92  
93 0 ▶ if( $self->{lastuser} && $self->{lastuser} ne $user ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lastuser"} and $self->{"lastuser"} ne $user) 0 0 0
Condition0%0/3
$self->{"lastuser"} and $self->{"lastuser"} ne $user
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"lastuser"} and $self->{"lastuser"} ne $user
$self->{"lastuser"} $self->{"lastuser"} ne $user
Truth table0%0/3
A and B
A= $self->{"lastuser"}B= $self->{"lastuser"} ne $user
ABresult
0X0
100
111
94 0 $self->clear;
95 }
96  
97 # Ugly stuff, but this keeps our place so we
98 # can determine the rep-based order of
99 # writeups across multiple search loads.
100  
101 0 ▶ $self->{rep_number} = 100000 - ($startat || 0);
Condition0%0/2
$startat || 0
l!l
00
MC/DC0%0/1
$startat || 0
$startat
Truth table0%0/2
A
A= $startat
Aresult
11
00
102  
103 my $handlers = {
104 0 ▶ 'wu' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
105 0 (my $a, my $b) = @_;
106 0 my $wu = new E2::Writeup;
107  
108 0 $wu->{type} = 'writeup';
109  
110 0 $wu->{createtime} = $b->{att}->{createtime};
111 0 $wu->{marked} = $b->{att}->{marked};
112 0 $wu->{hidden} = $b->{att}->{hidden};
113 0 $wu->{wrtype} = $b->{att}->{wrtype};
114  
115 0 $wu->{cool_count} = $b->{att}->{cools};
116  
117 0 ▶ if( my $rep = $b->first_child('rep') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rep = $b->first_child("rep")) 0 0 0
118 0 $wu->{rep}->{up} = $rep->{att}->{up};
119 0 $wu->{rep}->{down} = $rep->{att}->{down};
120 0 $wu->{rep}->{total} = $rep->text;
121 }
122
123 0 ▶ if( my $lnk = $b->first_child( 'e2link' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lnk = $b->first_child("e2link")) 0 0 0
124 0 $wu->{title} = $lnk->text;
125 0 $wu->{node_id} = $lnk->{att}->{node_id};
126 }
127  
128 0 ▶ if( my $parent = $b->first_child( 'parent' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $b->first_child("parent")) 0 0 0
129 0 my $l = $parent->first_child('e2link');
130 0 $wu->{parent} = $l->text;
131 0 $wu->{parent_id} = $l->{att}->{node_id};
132 }
133  
134 # We're going to add a value to the E2::Writeup.
135 # This is sort of a kludgy thing to do, but
136 # the situation (having to infer reputation
137 # based upon context) means we've got to store
138 # it somewhere.
139  
140 0 ▶ if( $sort_by eq 'rep' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sort_by eq 'rep') { } 0 0 0
141 0 $wu->{_rep_position} = $self->{rep_number}--;
142 } else {
143 0 $wu->{_rep_position} = 0;
144 }
145  
146 0 push @{ $self->{writeups} }, $wu;
147 }
148 0 };
149  
150 0 @{$self->{writeups}} = (); # clear
151  
152 return $self->parse(
153 'usersearch',
154 $handlers,
155 $self->{writeups},
156 0 %opt
157 );
158 }
159  
160 0 ▶sub sort_results {
Subroutine sort_results: not called CC=17 SCAR=57.2
Pod documented
161 0 ▶ my $self = shift or croak "Usage: sort_results E2USERSEARCH [, SORTBY [ , COUNT [ , STARTAT ] ] ]";
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Usage: sort_results E2USERSEARCH [, SORTBY [ , COUNT [ , STARTAT ] ] ]") 0 0 0
162 0 my $sortby = shift;
163 0 my $count = shift;
164 0 my $startat = shift;
165  
166 0 my $sort;
167  
168 0 ▶ warn "E2::UserSearch::sort_results\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG > 1 0 0 0
169  
170 # Define a bunch of sort routines
171 # (This whole thing is a mess..... ugly...... but it works)
172  
173 0 ▶ sub sort_by_creation {
Subroutine sort_by_creation: not called CC=6 SCAR=37.4
Pod undocumented
174 0 $b->{createtime} =~ /(....)-(..)-(..) (..):(..):(..)/;
175 0 (my $year1, my $month1, my $day1, my $hour1, my $min1, my $sec1 )
176 = ($1, $2, $3, $4, $5, $6);
177 0 $a->{createtime} =~ /(....)-(..)-(..) (..):(..):(..)/;
178 0 (my $year2, my $month2, my $day2, my $hour2, my $min2, my $sec2 )
179 = ($1, $2, $3, $4, $5, $6);
180  
181 0 ▶ $year1 <=> $year2 || $month1 <=> $month2 || $day1 <=> $day2 ||
Branch: 1 branch
BranchTrueFalseTotal
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2 or $sec1 <=> $sec2 0 0 0
Condition0%0/12
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2
l!l&&r!l&&!r
000
MC/DC0%0/5
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2
$year1 <=> $year2 $month1 <=> $month2 $day1 <=> $day2 $hour1 <=> $hour2 $min1 <=> $min2
Truth table0%0/6
A or B or C or D or E
A= $year1 <=> $year2B= $month1 <=> $month2C= $day1 <=> $day2D= $hour1 <=> $hour2E= $min1 <=> $min2
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
182 $hour1 <=> $hour2 || $min1 <=> $min2 || $sec1 <=> $sec2;
183 };
184  
185 0 ▶ sub sort_by_creation_reverse {
Subroutine sort_by_creation_reverse: not called CC=6 SCAR=37.4
Pod undocumented
186 0 $a->{createtime} =~ /(....)-(..)-(..) (..):(..):(..)/;
187 0 (my $year1, my $month1, my $day1, my $hour1, my $min1, my $sec1 )
188 = ($1, $2, $3, $4, $5, $6);
189 0 $b->{createtime} =~ /(....)-(..)-(..) (..):(..):(..)/;
190 0 (my $year2, my $month2, my $day2, my $hour2, my $min2, my $sec2 )
191 = ($1, $2, $3, $4, $5, $6);
192  
193 0 ▶ $year1 <=> $year2 || $month1 <=> $month2 || $day1 <=> $day2 ||
Branch: 1 branch
BranchTrueFalseTotal
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2 or $sec1 <=> $sec2 0 0 0
Condition0%0/12
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2
l!l&&r!l&&!r
000
$year1 <=> $year2 or $month1 <=> $month2
l!l&&r!l&&!r
000
MC/DC0%0/5
$year1 <=> $year2 or $month1 <=> $month2 or $day1 <=> $day2 or $hour1 <=> $hour2 or $min1 <=> $min2
$year1 <=> $year2 $month1 <=> $month2 $day1 <=> $day2 $hour1 <=> $hour2 $min1 <=> $min2
Truth table0%0/6
A or B or C or D or E
A= $year1 <=> $year2B= $month1 <=> $month2C= $day1 <=> $day2D= $hour1 <=> $hour2E= $min1 <=> $min2
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
194 $hour1 <=> $hour2 || $min1 <=> $min2 || $sec1 <=> $sec2;
195 };
196  
197 0 ▶ sub sort_by_title { $a->title cmp $b->title };
Subroutine sort_by_title: not called CC=1 SCAR=6.9
Pod undocumented
198  
199 0 ▶ sub sort_by_title_reverse { $b->title cmp $a->title };
Subroutine sort_by_title_reverse: not called CC=1 SCAR=6.9
Pod undocumented
200  
201 0 ▶ sub sort_by_rep { ($b->rep->{total} || 0) <=> ($a->rep->{total} || 0) };
Subroutine sort_by_rep: not called CC=3 SCAR=24.8
Pod undocumented
Condition0%0/4
$b->rep->{'total'} || 0
l!l
00
$a->rep->{'total'} || 0
l!l
00
MC/DC0%0/1
$b->rep->{'total'} || 0
$b->rep->{'total'}
MC/DC0%0/1
$a->rep->{'total'} || 0
$a->rep->{'total'}
Truth table0%0/2
A
A= $b->rep->{'total'}
Aresult
11
00
Truth table0%0/2
A
A= $a->rep->{'total'}
Aresult
11
00
202  
203 0 ▶ sub sort_by_rep_position { $b->{_rep_position} <=> $a->{_rep_position} };
Subroutine sort_by_rep_position: not called CC=1 SCAR=6.9
Pod undocumented
204  
205 0 ▶ sub sort_by_rep_position_reverse { $a->{_rep_position} <=> $b->{_rep_position} };
Subroutine sort_by_rep_position_reverse: not called CC=1 SCAR=6.9
Pod undocumented
206  
207 0 ▶ sub sort_by_rep_reverse { ($a->rep->{total} || 0) <=> ($b->rep->{total} || 0) };
Subroutine sort_by_rep_reverse: not called CC=3 SCAR=24.8
Pod undocumented
Condition0%0/4
$a->rep->{'total'} || 0
l!l
00
$b->rep->{'total'} || 0
l!l
00
MC/DC0%0/1
$a->rep->{'total'} || 0
$a->rep->{'total'}
MC/DC0%0/1
$b->rep->{'total'} || 0
$b->rep->{'total'}
Truth table0%0/2
A
A= $a->rep->{'total'}
Aresult
11
00
Truth table0%0/2
A
A= $b->rep->{'total'}
Aresult
11
00
208  
209 0 ▶ sub sort_by_cools { $b->cool_count <=> $a->cool_count };
Subroutine sort_by_cools: not called CC=1 SCAR=6.9
Pod undocumented
210  
211 0 ▶ sub sort_by_cools_reverse { $a->cools <=> $a->cools };
Subroutine sort_by_cools_reverse: not called CC=1 SCAR=6.9
Pod undocumented
212  
213 0 ▶ sub sort_by_random{ int(rand(3))-1 };
Subroutine sort_by_random: not called CC=1 SCAR=6.9
Pod undocumented
214
215 0 ▶ if( !$count ) { $count = -1; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($count) 0 0 0
216 0 ▶ if( !$startat ) { $startat = 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($startat) 0 0 0
217  
218 # Determine which way we want to sort and stick the method
219 # into the subroutine $sort.
220  
221 0 ▶ if( ! defined $sortby ) {
Branch: 11 branches
BranchTrueFalseTotal
if (not defined $sortby) { } 0 0 0
elsif (ref $sortby eq 'CODE') { } 0 0 0
elsif (lc $sortby eq 'creation') { } 0 0 0
elsif (lc $sortby eq 'title') { } 0 0 0
elsif (lc $sortby eq 'rep') { } 0 0 0
elsif (lc $sortby eq 'cools') { } 0 0 0
elsif (lc $sortby eq 'creation_reverse') { } 0 0 0
elsif (lc $sortby eq 'title_reverse') { } 0 0 0
elsif (lc $sortby eq 'rep_reverse') { } 0 0 0
elsif (lc $sortby eq 'cools_reverse') { } 0 0 0
elsif (lc $sortby eq 'random') { } 0 0 0
222 0 ▶ $sort = sub { sort_by_creation; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 0 } elsif( ref( $sortby ) eq 'CODE' ) {
224 0 $sort = $sortby;
225 } elsif( lc($sortby) eq "creation" ) {
226 0 ▶ $sort = sub { sort_by_creation; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
227 0 } elsif( lc($sortby) eq "title" ) {
228 0 ▶ $sort = sub { sort_by_title; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
229 0 } elsif( lc($sortby) eq "rep" ) {
230 0 ▶ $sort = sub { sort_by_rep || sort_by_rep_position || sort_by_creation; }
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
sort_by_rep() or sort_by_rep_position() or sort_by_creation() 0 0 0
Condition0%0/3
sort_by_rep() or sort_by_rep_position()
l!l&&r!l&&!r
000
MC/DC0%0/2
sort_by_rep() or sort_by_rep_position()
sort_by_rep() sort_by_rep_position()
Truth table0%0/3
A or B
A= sort_by_rep()B= sort_by_rep_position()
ABresult
1X1
011
000
231 0 } elsif( lc($sortby) eq "cools" ) {
232 0 ▶ $sort = sub { sort_by_cools || sort_by_rep || sort_by_rep_position; }
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
sort_by_cools() or sort_by_rep() or sort_by_rep_position() 0 0 0
Condition0%0/3
sort_by_cools() or sort_by_rep()
l!l&&r!l&&!r
000
MC/DC0%0/2
sort_by_cools() or sort_by_rep()
sort_by_cools() sort_by_rep()
Truth table0%0/3
A or B
A= sort_by_cools()B= sort_by_rep()
ABresult
1X1
011
000
233 0 } elsif( lc($sortby) eq "creation_reverse" ) {
234 0 ▶ $sort = sub { sort_by_creation_reverse; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
235 0 } elsif( lc($sortby) eq "title_reverse" ) {
236 0 ▶ $sort = sub { sort_by_title_reverse; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
237 0 } elsif( lc($sortby) eq "rep_reverse" ) {
238 0 ▶ $sort = sub { sort_by_rep_reverse || sort_by_rep_position_reverse ||
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
sort_by_rep_reverse() or sort_by_rep_position_reverse() or sort_by_creation_reverse() 0 0 0
Condition0%0/3
sort_by_rep_reverse() or sort_by_rep_position_reverse()
l!l&&r!l&&!r
000
MC/DC0%0/2
sort_by_rep_reverse() or sort_by_rep_position_reverse()
sort_by_rep_reverse() sort_by_rep_position_reverse()
Truth table0%0/3
A or B
A= sort_by_rep_reverse()B= sort_by_rep_position_reverse()
ABresult
1X1
011
000
239 sort_by_creation_reverse; }
240 0 } elsif( lc($sortby) eq "cools_reverse" ) {
241 0 ▶ $sort = sub { sort_by_cools_reverse || sort_by_rep_reverse ||
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
sort_by_cools_reverse() or sort_by_rep_reverse() or sort_by_rep_position_reverse() 0 0 0
Condition0%0/3
sort_by_cools_reverse() or sort_by_rep_reverse()
l!l&&r!l&&!r
000
MC/DC0%0/2
sort_by_cools_reverse() or sort_by_rep_reverse()
sort_by_cools_reverse() sort_by_rep_reverse()
Truth table0%0/3
A or B
A= sort_by_cools_reverse()B= sort_by_rep_reverse()
ABresult
1X1
011
000
242 sort_by_rep_position_reverse; }
243 0 } elsif( lc($sortby) eq "random" ) {
244 0 ▶ $sort = sub { sort_by_random; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
245 0 } else {
246 0 croak "Invalid sort type: $sortby";
247 }
248  
249 # Sort
250  
251 0 my @sorted = sort $sort @{ $self->{writeups} };
252  
253 0 ▶ if( $count == -1 ) { return @sorted; }
Branch: 1 branch
BranchTrueFalseTotal
if ($count == -1) 0 0 0
254  
255 0 return splice @sorted, $startat, $count;
256 }
257  
258 0 ▶sub compare {
Subroutine compare: not called CC=18 SCAR=58.3
Pod documented
259 0 ▶ my $self = shift or croak "Usage: compare E2USERSEARCH, OLDUSERSEARCH";
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Usage: compare E2USERSEARCH, OLDUSERSEARCH") 0 0 0
260 0 ▶ my $old = shift or croak "Usage: compare E2USERSEARCH, OLDUSERSEARCH";
Branch: 1 branch
BranchTrueFalseTotal
my $old = shift() or croak("Usage: compare E2USERSEARCH, OLDUSERSEARCH") 0 0 0
261  
262 0 ▶ warn "E2::UserSearch::compare\n" if $DEBUG > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG > 1 0 0 0
263  
264 0 ▶ if( ! $self->{writeups} || ! $old->{writeups} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"writeups"} and $old->{"writeups"}) 0 0 0
Condition0%0/3
$self->{"writeups"} and $old->{"writeups"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"writeups"} and $old->{"writeups"}
$self->{"writeups"} $old->{"writeups"}
Truth table0%0/3
A and B
A= $self->{"writeups"}B= $old->{"writeups"}
ABresult
0X0
100
111
265 0 ▶ warn"Usersearch not loaded" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $E2::UserSearch::DEBUG 0 0 0
266 0 return undef;
267 }
268  
269 0 my $stats;
270 my @changes;
271  
272 # Build a mapping of node_id to node for $old
273  
274 0 my %map;
275  
276 0 foreach( @{$old->{writeups}} ) {
277 0 $map{$_->node_id} = $_;
278 }
279  
280 0 foreach( $self->sort_results( 'rep' ) ) {
281  
282 0 my $writeup = {
283 title => $_->title,
284 node_id => $_->node_id,
285 parent => $_->parent,
286 parent_id => $_->parent_id,
287 rep => $_->rep,
288 cools => $_->cool_count
289 };
290  
291 # Get stats
292  
293 0 my $r = $_->rep->{total};
294  
295 0 ▶ if( !defined $stats->{min_rep} || $r < $stats->{min_rep} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stats->{"min_rep"} or $r < $stats->{"min_rep"}) 0 0 0
Condition0%0/3
not defined $stats->{"min_rep"} or $r < $stats->{"min_rep"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $stats->{"min_rep"} or $r < $stats->{"min_rep"}
not defined $stats->{"min_rep"} $r < $stats->{"min_rep"}
Truth table0%0/3
not(A) or B
A= not defined $stats->{"min_rep"}B= $r < $stats->{"min_rep"}
ABresult
1X1
011
000
296 0 $stats->{min_rep} = $r;
297 }
298  
299 0 ▶ if( !defined $stats->{max_rep} || $r > $stats->{max_rep} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stats->{"max_rep"} or $r > $stats->{"max_rep"}) 0 0 0
Condition0%0/3
not defined $stats->{"max_rep"} or $r > $stats->{"max_rep"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $stats->{"max_rep"} or $r > $stats->{"max_rep"}
not defined $stats->{"max_rep"} $r > $stats->{"max_rep"}
Truth table0%0/3
not(A) or B
A= not defined $stats->{"max_rep"}B= $r > $stats->{"max_rep"}
ABresult
1X1
011
000
300 0 $stats->{max_rep} = $r;
301 }
302  
303 # Store statistics
304  
305 0 $stats->{total_rep} += $r;
306 0 $stats->{total_cools} += $_->cool_count;
307 0 $stats->{$_->wrtype} += 1;
308  
309 # Get changes
310  
311 0 my $id = $_->node_id;
312 0 my $changed = undef;
313
314 0 ▶ if( !$map{$id} ) { # New writeup (not yet stored)
Branch: 1 branch
BranchTrueFalseTotal
if (not $map{$id}) { } 0 0 0
315 0 $writeup->{new} = 1;
316 0 $writeup->{change_up} = $_->rep->{up};
317 0 $writeup->{change_down} = $_->rep->{down};
318 0 $writeup->{change_cools} = $_->cool_count;
319  
320 0 $changed = 1;
321  
322 } else {
323
324 0 ▶ sub wr_diff {
Subroutine wr_diff: not called CC=3 SCAR=24.8
Pod undocumented
325 0 my ($a, $b) = @_;
326 return $a->rep->{up} != $b->rep->{up} ||
327 $a->rep->{down} != $b->rep->{down} ||
328 0 ▶ $a->cool_count != $b->cool_count;
Condition0%0/6
$a->rep->{'up'} != $b->rep->{'up'} || $a->rep->{'down'} != $b->rep->{'down'} || $a->cool_count != $b->cool_count
l!l&&r!l&&!r
000
$a->rep->{"up"} != $b->rep->{"up"} or $a->rep->{"down"} != $b->rep->{"down"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$a->rep->{'up'} != $b->rep->{'up'} || $a->rep->{'down'} != $b->rep->{'down'} || $a->cool_count != $b->cool_count
$a->rep->{"up"} != $b->rep->{"up"} $a->rep->{"down"} != $b->rep->{"down"} $a->cool_count != $b->cool_count
Truth table0%0/4
A or B || C
A= $a->rep->{"up"} != $b->rep->{"up"}B= $a->rep->{"down"} != $b->rep->{"down"}C= $a->cool_count != $b->cool_count
ABCresult
1XX1
01X1
0011
0000
329 }
330  
331 0 ▶ if( wr_diff( $_, $map{$id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wr_diff($_, $map{$id})) 0 0 0
332
333 $writeup->{change_up} = $_->rep->{up} -
334 0 $map{$id}->rep->{up};
335 $writeup->{change_down} = $_->rep->{down} -
336 0 $map{$id}->rep->{down};
337 $writeup->{change_cools} = $_->cool_count -
338 0 $map{$id}->cool_count;
339  
340 0 $changed = 1;
341 }
342  
343 0 ▶ if( $_->title ne $map{$id}->title ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->title ne $map{$id}->title) 0 0 0
344 0 $writeup->{old_title} = $map{$id}->title;
345
346 0 $changed = 1;
347 }
348  
349 0 delete $map{$id};
350 }
351
352 0 ▶ push @changes, $writeup if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
353 }
354  
355 # Now store removed writeups
356  
357 0 foreach( keys %map ) {
358 0 push @changes, {
359 title => $_->title,
360 rep => $_->rep,
361 cools => $_->cools,
362 removed => 1
363 }
364 }
365
366 # Store
367  
368 0 $self->{stats} = $stats;
369  
370 0 return @changes;
371 }
372  
373 0 ▶sub stats {
Subroutine stats: not called CC=2 SCAR=17.9
Pod documented
374 0 ▶ my $self = shift or croak "Usage: stats E2USERSEARCH";
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Usage: stats E2USERSEARCH") 0 0 0
375  
376 0 return $self->{stats};
377 }
378  
379 1 1;
380 __END__
« Interface.pm ↑ Summary Writeup.pm »