blib/lib/App/KGB/Commit.pm

filter: Statementstmt 52.9% 18 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 36.2% 25 / 69 CC 9 SCAR 31.1
CC
9
Cov
33%
new
42.0
stringify
20.0
BEGIN
1.0
CRAP 22.5
« blib/lib/App/KGB/Painter.pm ↑ Summary blib/lib/App/KGB/Client/RelayMsg.pm »
1 # vim: ts=4:sw=4:et:ai:sts=4
2 #
3 # KGB - an IRC bot helping collaboration
4 # Copyright © 2008 Martina Ferrari
5 # Copyright © 2009 Damyan Ivanov
6 #
7 # This program is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # this program; if not, write to the Free Software Foundation, Inc., 51
19 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package App::KGB::Commit;
21  
22 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 8 our $VERSION = 1.27;
26  
27 =head1 NAME
28  
29 App::KGB::Commit - a single commit
30  
31 =head1 SYNOPSIS
32  
33 my $c = App::KGB::Commit->new(
34 { id => 4536,
35 changes => ["(M)/there"],
36 log => "fixed /there",
37 author => "My Self <mself@here.at>",
38 branch => "trunk",
39 module => "test",
40 }
41 );
42  
43 =head1 DESCRIPTION
44  
45 B<App::KGB::Change> encapsulates a single commit. A commit has several
46 properties: an ID, a list of changes, an author, a log message, optionally also
47 a branch and a module.
48  
49 =head1 FIELDS
50  
51 =over
52  
53 =item B<id>
54  
55 The commit ID that uniquely identifies it in the repository (if applicable).
56  
57 =item B<changes>
58  
59 An arrayref of L<App::KGB::Change> instances or other objects that behave as
60 strings.
61  
62 =item B<author>
63  
64 =item B<log>
65  
66 =item B<branch>
67  
68 =item B<module>
69  
70 =back
71  
72 =cut
73  
74 8 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 8 __PACKAGE__->mk_accessors( qw( id changes log author author_name author_via branch module ) );
76  
77 8 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 =head1 CONSTRUCTOR
80  
81 =head2 new ( { I<initial field values> } )
82  
83 Standard constructor. Accepts a hashref with field values.
84  
85 =cut
86  
87 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
88 0 my $class = shift;
89 0 my $self = $class->SUPER::new(@_);
90  
91 0 ▶ not defined( $self->changes )
Branch: 1 branch
BranchTrueFalseTotal
not defined $self->changes or ref $self->changes and ref $self->changes eq "ARRAY" or confess("'changes' must be an arrayref") 0 0 0
Condition0%0/6
not defined $self->changes or ref $self->changes and ref $self->changes eq "ARRAY"
l!l&&r!l&&!r
000
ref $self->changes and ref $self->changes eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $self->changes or ref $self->changes and ref $self->changes eq "ARRAY"
not defined $self->changes ref $self->changes ref $self->changes eq "ARRAY"
Truth table0%0/4
not(A) or B and C
A= not defined $self->changesB= ref $self->changesC= ref $self->changes eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
92 or ref( $self->changes ) and ref( $self->changes ) eq 'ARRAY'
93 or confess "'changes' must be an arrayref";
94  
95 0 my $log = $self->log;
96 0 ▶ utf8::decode($log)
Branch: 1 branch
BranchTrueFalseTotal
if defined $log 0 0 0
Condition0%0/6
defined $log && (utf8::decode($log) || ($log = '(log message is not valid UTF-8)'))
!ll&&!rl&&r
000
utf8::decode($log) or $log = "(log message is not valid UTF-8)"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $log && (utf8::decode($log) || ($log = '(log message is not valid UTF-8)'))
defined $log utf8::decode($log) $log = "(log message is not valid UTF-8)"
Truth table0%0/4
A && B or C
A= defined $logB= utf8::decode($log)C= $log = "(log message is not valid UTF-8)"
ABCresult
0XX0
1000
11X1
1011
97 or $log = "(log message is not valid UTF-8)"
98 if defined($log);
99 0 $self->log($log);
100  
101 0 return $self;
102 }
103  
104 =head1 OVERLOADS
105  
106 =over
107  
108 =item stringify
109  
110 Returns a text representation of the commit object
111  
112 =back
113  
114 =cut
115  
116 8 ▶use overload '""' => \&stringify;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 0 ▶sub stringify {
Subroutine stringify: not called CC=4 SCAR=30.0
Pod documented
119 0 my $self = shift;
120  
121 0 my @data;
122 0 for my $f (qw(id changes log author author_name branch module)) {
123 0 ▶ next unless $self->$f;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$f 0 0 0
124  
125 0 ▶ if ( $f eq 'changes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq 'changes') { } 0 0 0
126 0 push @data, "changes=[" . join( ', ', @{ $self->$f } ) . "]";
127 }
128 else {
129 0 push @data, "$f=" . $self->$f;
130 }
131 }
132  
133 0 return ref($self) . '(' . join( ', ', @data ) . ')';
134 }
135  
136 8 1;
« blib/lib/App/KGB/Painter.pm ↑ Summary blib/lib/App/KGB/Client/RelayMsg.pm »