| 1 | package DBIx::Changeset::History; | ||||||||||||||||||||
| 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 | |||||||||||||||||||||
| 8 | 5 | ▶ | use Exception::Class::DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use DBIx::Changeset::HistoryRecord; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 5 | ▶ | use vars qw{$VERSION}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 5 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 5 | $VERSION = '1.11'; | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | DBIx::Changeset::History - Object to query the changeset record log | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | Object to query the changeset record log | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Perhaps a little code snippet. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | use DBIx::Changeset::History; | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | my $foo = DBIx::Changeset::History->new($opts); | ||||||||||||||||||||
| 29 | ... | ||||||||||||||||||||
| 30 | $foo->retrieve_all(); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 5 | my @ATTRS = qw/dbh records current_index pb/; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 5 | __PACKAGE__->mk_accessors(@ATTRS); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head2 new | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||
| 46 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||
| 47 | 2 | my($proto, $fields) = @_; | |||||||||||||||||||
| 48 | 2 | ▶ | my($class) = ref $proto || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2 | ▶ | DBIx::Changeset::Exception::ObjectCreateException->throw(error => 'Missing required db connection fields') unless defined $fields; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 2 | my $self = bless {%$fields}, $class; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 2 | $self->_connect_to_db; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =head2 init_history_table | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | This method loads the sql for creation of the history table | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||
| 64 | 0 | ▶ | sub init_history_table { | ||||||||||||||||||
|
Subroutine
init_history_table: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | $self->_connect_to_db() unless defined $self->dbh(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | ### get the table create query | ||||||||||||||||||||
| 70 | 0 | my $q = $self->pb->query('create_changeset_history'); | |||||||||||||||||||
| 71 | ### execute it | ||||||||||||||||||||
| 72 | 0 | $q->execute(); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | $q->finish(); | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | return; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =head2 retrieve_all | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | Get a list of the history records from the database. | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub retrieve_all { | ||||||||||||||||||
|
Subroutine
retrieve_all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | $self->_connect_to_db() unless defined $self->dbh(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | my $q = $self->pb()->query('get_all_changeset_history'); | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | my @records; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | while(my $row = $q->fetchrow_hashref() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | push @records, $row; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | $q->finish(); | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | $self->records(\@records); | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =head2 retrieve | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub retrieve { | ||||||||||||||||||
|
Subroutine
retrieve: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 110 | 0 | my ($self, $uid) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 next | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||
| 118 | 0 | ▶ | sub next { | ||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||
| 120 | 0 | ▶ | if ( not defined $self->current_index ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 121 | 0 | $self->current_index(0); | |||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||
| 123 | 0 | $self->current_index($self->current_index + 1); | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | 0 | my $db_entry = $self->records->[$self->current_index]; | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | my $hrec = DBIx::Changeset::HistoryRecord->new({ | ||||||||||||||||||||
| 128 | history_db_dsn => $self->history_db_dsn, | ||||||||||||||||||||
| 129 | history_db_user => $self->history_db_user, | ||||||||||||||||||||
| 130 | history_db_password => $self->history_db_password, | ||||||||||||||||||||
| 131 | 0 | %{$db_entry}, | |||||||||||||||||||
| 132 | }); | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | return $hrec; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =head2 add_history_record | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||
| 140 | 0 | ▶ | sub add_history_record { | ||||||||||||||||||
|
Subroutine
add_history_record: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 141 | 0 | my ($self,$record) = @_; | |||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | my $hrec = DBIx::Changeset::HistoryRecord->new({history_db_dsn => $self->history_db_dsn, history_db_user => $self->history_db_user, history_db_password => $self->history_db_password}); | |||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 0 | $hrec->write($record); | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | return $hrec; | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head2 total | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||
| 153 | 0 | ▶ | sub total { | ||||||||||||||||||
|
Subroutine
total: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 154 | 0 | my $self = shift; | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | return scalar(@{$self->records}); | |||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head2 reset | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||
| 162 | 0 | ▶ | sub reset { | ||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 163 | 0 | my $self = shift; | |||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 0 | $self->current_index(undef); | |||||||||||||||||||
| 166 | 0 | return; | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 2 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.6
| |||||||||||||||||||||
| 170 | 2 | my $self = shift; | |||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 2 | ▶ | if ( defined $self->dbh ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 173 | 0 | $self->dbh->disconnect(); | |||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | 2 | return; | |||||||||||||||||||
| 177 | } | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | Copyright 2004-2008 Grox Pty Ltd. | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 184 | under the same terms as Perl itself. | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 5 | 1; # End of DBIx::Changeset | |||||||||||||||||||