blib/lib/DBIx/Changeset/HistoryRecord.pm

filter: Statementstmt 43.0% 28 / 65 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 100% 3 / 3 totaltotal 39.2% 40 / 102 CC 11 SCAR 25.2
CC
11
Cov
33%
read
30.0
write
20.0
new
12.0
CRAP 12.5
« blib/lib/DBIx/Changeset/App/Command/compare.pm ↑ Summary blib/lib/DBIx/Changeset/App/Command/bootstrap.pm »
1 package DBIx::Changeset::HistoryRecord;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use base qw/DBIx::Changeset/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Exception::Class::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 $VERSION = '1.11';
15 }
16  
17 =head1 NAME
18  
19 DBIx::Changeset::HistoryRecord - Object to query a changeset record log entry
20  
21 =head1 SYNOPSIS
22  
23 Object to query a changeset record log entry
24  
25 use DBIx::Changeset::HistoryRecord;
26  
27 my $foo = DBIx::Changeset::HistoryRecord->new();
28 ...
29 $foo->find_all();
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 =cut
36 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
37 0 my($proto, $fields) = @_;
38 0 ▶ my($class) = ref $proto || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
39  
40 0 ▶ DBIx::Changeset::Exception::ObjectCreateException->throw(error => 'Missing required db connection fields') unless defined $fields;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields 0 0 0
41
42 0 my $self = bless {%$fields}, $class;
43  
44 0 return $self;
45 }
46  
47 =head2 read
48  
49 =cut
50 0 ▶sub read {
Subroutine read: not called CC=5 SCAR=34.0
Pod documented
51 0 my ($self, $uid) = @_;
52  
53 ## check for a uid
54 0 ▶ DBIx::Changeset::Exception::ReadHistoryRecordException->throw(error => 'Need a uid to read') unless defined $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uid 0 0 0
55
56 0 ▶ $self->_connect_to_db() unless defined $self->dbh();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->dbh 0 0 0
57  
58 ## right we got a uid so do a search
59 0 my $q = $self->pb()->query('get_changeset_record', { id => $uid });
60  
61 0 my $hrecord = $q->fetchrow_hashref;
62  
63 0 ▶ DBIx::Changeset::Exception::ReadHistoryRecordException->throw(error => "No record found with uid of $uid") unless defined $hrecord;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hrecord 0 0 0
64  
65 # set the accessors
66 0 foreach my $key (qw(id filename md5 version skipped_b forced_b modify_ts create_ts)) {
67 0 $self->$key($hrecord->{$key});
68 }
69  
70 0 $q->finish();
71
72 0 return;
73 }
74  
75 =head2 write
76  
77 =cut
78 0 ▶sub write {
Subroutine write: not called CC=4 SCAR=30.0
Pod documented
79 0 my ($self, $record) = @_;
80  
81 0 ▶ DBIx::Changeset::Exception::WriteHistoryRecordException->throw(error => 'No DBIx::Changeset::Record object provided') unless defined $record;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record 0 0 0
82  
83 0 ▶ $self->_connect_to_db() unless defined $self->dbh();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->dbh 0 0 0
84  
85 ### does a record exist already
86 0 my $q = $self->pb()->query('get_changeset_record', { id => $record->id });
87  
88 ### work out filename
89 0 my $filename = File::Spec->catfile($record->changeset_location, $record->uri);
90  
91 ### md5
92 0 my $md5 = $record->md5();
93 ### timestamp
94 0 my $dt = DateTime->now();
95 0 my $ts = $dt->ymd . ' ' . $dt->hms;
96
97 0 my $hrecord = $q->fetchrow_hashref;
98  
99 0 ▶ if ( defined($hrecord) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hrecord) { } 0 0 0
100 ### update
101 my $q_ = $self->pb()->query('update_changeset_record', {
102 filename => $filename,
103 md5 => $md5,
104 modify_ts => $ts,
105 0 id => $hrecord->{'id'},
106 });
107 0 $q_->execute();
108 0 $q_->finish();
109 } else {
110 ### create
111 0 my $q_ = $self->pb()->query('create_changeset_record', {
112 id => $record->id,
113 filename => $filename,
114 md5 => $md5,
115 modify_ts => $ts,
116 create_ts => $ts,
117 version => 1,
118 });
119  
120 0 $q_->execute();
121 0 $q_->finish();
122 }
123  
124 0 $q->finish();
125  
126 0 return;
127 }
128  
129 =head1 ACCESSORS
130  
131 =head2 id
132 The id of this record (matches the DBIx::Changeset::Record uid)
133 args:
134 string
135 returns:
136 string
137  
138 =head2 dbh
139 The dbh connection to the historyrecord database
140 args:
141 DBD::H
142 returns:
143 DBD::H
144  
145 =head2 filename
146 The uri of the matching changeset record
147 args:
148 string
149 returns:
150 string
151  
152 =head2 md5
153 The md5 hash of the Record content when it was updated
154 args:
155 string
156 returns:
157 string
158  
159 =head2 forced_b
160 records wether this was a forced update
161 args:
162 bool
163 returns:
164 bool
165  
166 =head2 skipped_b
167 records wether this update was skipped
168 args:
169 bool
170 returns:
171 bool
172  
173 =head2 modify_ts
174 records the timestamp of when this record was last modified
175 args:
176 timestamp
177 returns:
178 timestamp
179  
180 =head2 modify_ts
181 records the timestamp of when this record was created
182 args:
183 timestamp
184 returns:
185 timestamp
186 =head2 pb
187 the data phrasebook used for loading the correct sql
188 args:
189 phrasebook object
190 returns:
191 phreasebook object
192  
193 =cut
194  
195 5 my @ACCESSORS = qw/dbh id filename md5 forced_b skipped_b version modify_ts create_ts pb/;
196 5 __PACKAGE__->mk_accessors(@ACCESSORS);
197  
198 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
199 0 my $self = shift;
200  
201 0 ▶ if ( defined $self->dbh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->dbh) 0 0 0
202 0 $self->dbh->disconnect();
203 }
204  
205 0 return;
206 }
207  
208 =head1 COPYRIGHT & LICENSE
209  
210 Copyright 2004-2008 Grox Pty Ltd.
211  
212 This program is free software; you can redistribute it and/or modify it
213 under the same terms as Perl itself.
214  
215 The full text of the license can be found in the LICENSE file included with this module.
216  
217 =cut
218  
219 5 1; # End of DBIx::Changeset
« blib/lib/DBIx/Changeset/App/Command/compare.pm ↑ Summary blib/lib/DBIx/Changeset/App/Command/bootstrap.pm »