blib/lib/DBIx/Changeset/Record.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 92.8% 13 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 83.3% 10 / 12 Podpod 100% 6 / 6 totaltotal 94.5% 86 / 91 CC 10 SCAR 9.6
CC
10
Cov
96%
init
4.0
get
4.0
generate_uid
3.0
CRAP 2.6
« blib/lib/DBIx/Changeset.pm ↑ Summary blib/lib/DBIx/Changeset/Collection.pm »
1 package DBIx::Changeset::Record;
2  
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use base qw/Class::Factory DBIx::Changeset/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 $VERSION = '1.11';
12 }
13  
14 =head1 NAME
15  
16 DBIx::Changeset::Record - Factory Interface to changeset files
17  
18 =cut
19  
20 =head1 SYNOPSIS
21  
22 Factory Interface to changeset files
23  
24 Perhaps a little code snippet.
25  
26 use DBIx::Changeset::Record;
27  
28 my $foo = DBIx::Changeset::Record->new('type', $opts);
29 ...
30 $foo->read('/moose/moose.sql');
31  
32 =head1 INTERFACE
33  
34 =head2 read
35 This is the read interface implement in your own class
36 =cut
37 0 ▶sub read {
Subroutine read: not called CC=1 SCAR=6.9
Pod documented
38 0 die "Define read() in implementation"
39 }
40  
41 =head2 write
42 This is the write interface implement in your own class
43 =cut
44 0 ▶sub write {
Subroutine write: not called CC=1 SCAR=6.9
Pod documented
45 0 die "Define write() in implementation"
46 }
47  
48 =head1 METHODS
49  
50 =head2 init
51 Called automatically to intialise the factory objects takes params passed to new and assigns them to
52 accessors if they exist
53 =cut
54  
55 31 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod documented
56 31 my ( $self, $params ) = @_;
57  
58 31 ▶ DBIx::Changeset::Exception::ObjectCreateException->throw( error => 'Attempt to create Record Object without a uri.' ) unless defined $params->{'uri'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"uri"} 2 29 31
59  
60 29 foreach my $field ( keys %{$params} ) {
61 52 ▶ $self->{ $field } = $params->{ $field } if ( $self->can($field) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($field) 52 0 52
62 }
63 29 return $self;
64 }
65  
66 =head2 validate
67 Validate that the file data is correct
68 =cut
69 11 ▶sub validate {
Subroutine validate: called CC=2 SCAR=6.9
Pod documented
70 11 my ($self) = @_;
71 11 my $file = $self->read($self->uri);
72
73 11 ▶ if ($file =~ m!^/\*.*?tag:\s*(\S+)!mx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[^/\*.*?tag:\s*(\S+)]mx) { } 10 1 11
74 10 $self->id($1);
75 10 $self->valid(1);
76 } else {
77 1 $self->valid(0);
78 }
79
80 11 return;
81 }
82  
83 =head2 generate_uid
84 Generates a uid writing it to the file
85 =cut
86 4 ▶sub generate_uid {
Subroutine generate_uid: called CC=3 SCAR=11.0
Pod documented
87 4 my ($self, $data) = @_;
88 4 my $ug = new Data::UUID;
89 4 ▶ $data = $self->read() unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 2 2 4
90 4 $self->id($ug->to_string($ug->create()));
91 ### check for existing id
92 4 ▶ if ($data =~ m!^/\*.*?tag:\s*(\S+)!mx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ m[^/\*.*?tag:\s*(\S+)]mx) { } 2 2 4
93 ### replace it
94 2 my $id = sprintf('* tag: %s', $self->id);
95 2 $data =~ s!\*.*?tag:\s*(\S+)!$id!exm;
96 } else {
97 ### tack it on the end
98 2 $data .= sprintf("\n/* tag: %s */\n",$self->id);
99 }
100 4 $self->write($data);
101 3 return;
102 }
103  
104 =head1 ACCESSORS
105  
106 =head2 valid
107 Has this file been processed as valid default false
108 args:
109 bool
110 returns:
111 bool
112  
113 =head2 skipped
114 Has this file been skipped default false
115 args:
116 bool
117 returns:
118 bool
119  
120 =head2 outstanding
121 Is this file outstanding default false
122 args:
123 bool
124 returns:
125 bool
126  
127 =head2 id
128 The UID of the file
129 args:
130 bool
131 returns:
132 bool
133  
134 =head2 uri
135 The location of the file data * READ ONLY *
136 args:
137 string
138 returns:
139 string
140 =cut
141  
142 11 my @ACCESSORS = qw/id valid skipped outstanding forced/;
143 11 __PACKAGE__->mk_accessors(@ACCESSORS);
144  
145 11 my @RO_ACCESSORS = qw/uri/;
146 11 __PACKAGE__->mk_ro_accessors(@RO_ACCESSORS);
147  
148 =head1 OVERRIDEN METHODS
149  
150 =head2 get
151  
152 Override the ger accessor for id and valid so that if they are undef
153 validate is called.
154  
155 =cut
156  
157 115 ▶sub get {
Subroutine get: called CC=4 SCAR=13.9
Pod documented
158 115 my ($self, $key) = @_;
159  
160 115 ▶ if ( ($key eq 'id') || ($key eq 'valid') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "id" or $key eq "valid") 32 83 115
Condition100%3/3
$key eq "id" or $key eq "valid"
l!l&&r!l&&!r
191383
MC/DC100%2/2
$key eq "id" or $key eq "valid"
$key eq "id" $key eq "valid"
Truth table100%3/3
A or B
A= $key eq "id"B= $key eq "valid"
ABresult
1X1
011
000
161 32 my $value = $self->SUPER::get($key);
162 32 ▶ unless ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 9 23 32
163 9 $self->validate();
164 }
165 }
166 115 return $self->SUPER::get($key);
167 }
168  
169  
170 =head1 TYPES
171 Default types included
172  
173 =head2 disk
174 Simply reads files from disk expects a uri of a filename
175 =cut
176 11 __PACKAGE__->register_factory_type( disk => 'DBIx::Changeset::Record::Disk' );
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 11 1; # End of DBIx::Changeset
« blib/lib/DBIx/Changeset.pm ↑ Summary blib/lib/DBIx/Changeset/Collection.pm »