blib/lib/DBIx/Changeset/Collection.pm

filter: Statementstmt 100% 67 / 67 Branchbran 61.1% 11 / 18 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 84.2% 16 / 19 Podpod 100% 14 / 14 totaltotal 86.4% 115 / 133 CC 14 SCAR 8.8
CC
14
Cov
88%
next_outstanding
4.6
init
4.0
next_valid
3.1
CRAP 2.4
« blib/lib/DBIx/Changeset/Record.pm ↑ Summary blib/lib/DBIx/Changeset/Collection/Disk.pm »
1 package DBIx::Changeset::Collection;
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/Class::Factory DBIx::Changeset/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 $VERSION = '1.11';
11 }
12  
13 =head1 NAME
14  
15 DBIx::Changeset::Collection - Factory Interface to a collection of changeset files
16  
17 =head1 SYNOPSIS
18  
19 Factory Interface to a collection of changeset files
20  
21 Perhaps a little code snippet.
22  
23 use DBIx::Changeset::Collection;
24  
25 my $foo = DBIx::Changeset::Collection->new('type', $opts);
26 ...
27 $foo->find_all();
28  
29 =head1 ATTRIBUTES
30  
31 =cut
32  
33 5 my @ATTRS = qw/files current_index/;
34  
35 5 __PACKAGE__->mk_accessors(@ATTRS);
36  
37  
38 =head1 INTERFACE
39  
40 =head2 retrieve_all
41 This is the find_all interface to implement in your own class
42 =cut
43 0 ▶sub retrieve_all {
Subroutine retrieve_all: not called CC=1 SCAR=0.0
Pod documented
44 }
45  
46  
47  
48 =head2 retrieve_like
49 This is the find_like interface to implement in your own class
50 =cut
51 0 ▶sub retrieve_like {
Subroutine retrieve_like: not called CC=1 SCAR=0.0
Pod documented
52 }
53  
54 =head2 add_changeset
55 This is the add_changeset interface implement in your own class
56 creates a new record based on uri and adds to end of current file list
57 =cut
58 0 ▶sub add_changeset {
Subroutine add_changeset: not called CC=1 SCAR=0.0
Pod documented
59 }
60  
61 =head1 METHODS
62  
63 =head2 init
64 Called automatically to intialise the factory objects takes params passed to new and assigns them to
65 accessors if they exist
66 =cut
67  
68 6 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod documented
69 6 my ( $self, $params ) = @_;
70
71 6 ▶ DBIx::Changeset::Exception::ObjectCreateException->throw( error => 'Attempt to create Collection Object without a changeset_location.' ) unless defined $params->{'changeset_location'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"changeset_location"} 2 4 6
72
73 4 foreach my $field ( keys %{$params} ) {
74 5 ▶ $self->{ $field } = $params->{ $field } if ( $self->can($field) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($field) 5 0 5
75 }
76 4 return $self;
77 }
78  
79 =head2 retrieve
80 Retrieve a name file
81 =cut
82 1 ▶sub retrieve {
Subroutine retrieve: called CC=1 SCAR=0.0
Pod documented
83 1 my ($self, $uri) = @_;
84  
85 1 $self->retrieve_like(qr/$uri/xm);
86  
87 1 return;
88 }
89  
90 =head2 next
91 The next file
92 =cut
93 5 ▶sub next {
Subroutine next: called CC=2 SCAR=6.9
Pod documented
94 5 my $self = shift;
95 5 ▶ if ( not defined $self->current_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->current_index) { } 2 3 5
96 2 $self->current_index(0);
97 } else {
98 3 $self->current_index($self->current_index + 1);
99 }
100 5 return $self->files->[$self->current_index];
101 }
102  
103 =head2 next_outstanding
104 Returns the next file with an outstanding flag set
105 =cut
106 1 ▶sub next_outstanding {
Subroutine next_outstanding: called CC=4 SCAR=15.2
Pod documented
107 1 my $self = shift;
108
109 1 my $outstanding;
110 1 ▶ while ( $outstanding = $self->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($outstanding = $self->next) 1 0 1
111 1 ▶ last if ( (defined $outstanding->outstanding()) && ($outstanding->outstanding() == 1) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $outstanding->outstanding and $outstanding->outstanding == 1 1 0 1
Condition33%1/3
defined $outstanding->outstanding and $outstanding->outstanding == 1
!ll&&!rl&&r
001
MC/DC0%0/2
defined $outstanding->outstanding and $outstanding->outstanding == 1
defined $outstanding->outstanding $outstanding->outstanding == 1
Truth table33%1/3
A and B
A= defined $outstanding->outstandingB= $outstanding->outstanding == 1
ABresult
0X0
100
111
112 }
113 1 return $outstanding;
114 }
115  
116 =head2 next_valid
117 Returns the next file with a valid flag set
118 =cut
119 1 ▶sub next_valid {
Subroutine next_valid: called CC=3 SCAR=11.3
Pod documented
120 1 my $self = shift;
121  
122 1 my $valid;
123 1 ▶ while ( $valid = $self->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid = $self->next) 1 0 1
124 1 ▶ last if $valid->valid() == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $valid->valid == 1 1 0 1
125 }
126 1 return $valid;
127  
128 }
129  
130 =head2 next_skipped
131 Returns the next file with a skipped flag set
132 =cut
133 1 ▶sub next_skipped {
Subroutine next_skipped: called CC=3 SCAR=11.3
Pod documented
134 1 my $self = shift;
135  
136 1 my $skipped;
137 1 ▶ while ( $skipped = $self->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skipped = $self->next) 1 0 1
138 1 ▶ last if $skipped->skipped() == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $skipped->skipped == 1 1 0 1
139 }
140 1 return $skipped;
141 }
142  
143 =head2 reset
144 Returns to the first record in the collection
145 =cut
146 1 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
147 1 my $self = shift;
148  
149 1 $self->current_index(undef);
150 1 return;
151 }
152  
153 =head2 total
154 The total number of records
155 =cut
156 6 ▶sub total {
Subroutine total: called CC=1 SCAR=0.0
Pod documented
157 6 my $self = shift;
158  
159 6 return scalar(@{$self->files});
160 }
161  
162 =head2 total_outstanding
163 Returns the total number of records with outstanding flag set
164 =cut
165 1 ▶sub total_outstanding {
Subroutine total_outstanding: called CC=2 SCAR=7.0
Pod documented
166 1 my $self = shift;
167  
168 1 ▶ my @total = grep { defined $_->outstanding && $_->outstanding == 1 } @{$self->files};
Condition66%2/3
defined $_->outstanding && $_->outstanding == 1
!ll&&!rl&&r
301
MC/DC50%1/2
defined $_->outstanding && $_->outstanding == 1
defined $_->outstanding $_->outstanding == 1
Truth table66%2/3
A && B
A= defined $_->outstandingB= $_->outstanding == 1
ABresult
0X0
100
111
169  
170 1 return scalar(@total);
171 }
172  
173 =head2 total_valid
174 Returns the total number of records with valid flag set
175 =cut
176 1 ▶sub total_valid {
Subroutine total_valid: called CC=1 SCAR=0.0
Pod documented
177 1 my $self = shift;
178  
179 1 my @total = grep { $_->valid == 1 } @{$self->files};
180  
181 1 return scalar(@total);
182 }
183  
184 =head2 total_skipped
185 Returns the total number of records with skipped flag set
186 =cut
187 1 ▶sub total_skipped {
Subroutine total_skipped: called CC=2 SCAR=7.0
Pod documented
188 1 my $self = shift;
189  
190 1 ▶ my @total = grep { defined $_->skipped && $_->skipped == 1 } @{$self->files};
Condition66%2/3
defined $_->skipped && $_->skipped == 1
!ll&&!rl&&r
301
MC/DC50%1/2
defined $_->skipped && $_->skipped == 1
defined $_->skipped $_->skipped == 1
Truth table66%2/3
A && B
A= defined $_->skippedB= $_->skipped == 1
ABresult
0X0
100
111
191  
192 1 return scalar(@total);
193 }
194  
195 =head1 TYPES
196 Default types included
197  
198 =head2 disk
199 Simply reads files from disk expects a changeset_location of directories
200 =cut
201 5 __PACKAGE__->register_factory_type( disk => 'DBIx::Changeset::Collection::Disk' );
202  
203 =head1 COPYRIGHT & LICENSE
204  
205 Copyright 2004-2008 Grox Pty Ltd.
206  
207 This program is free software; you can redistribute it and/or modify it
208 under the same terms as Perl itself.
209  
210 The full text of the license can be found in the LICENSE file included with this module.
211  
212 =cut
213  
214 5 1; # End of DBIx::Changeset
« blib/lib/DBIx/Changeset/Record.pm ↑ Summary blib/lib/DBIx/Changeset/Collection/Disk.pm »