Schema/PgLog.pm

filter: Statementstmt 32.8% 24 / 73 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 46.1% 6 / 13 Podpod 100% 5 / 5 totaltotal 29.1% 35 / 120 CC 12 SCAR 24.8
CC
12
Cov
25%
connection
20.0
txn_do
20.0
find_or_create_pg_log_schema_template
20.0
CRAP 12.0
« PgLog.pm ↑ Summary ResultSet/PgLog.pm »
1 package DBIx::Class::Schema::PgLog;
2  
3 3 ▶use base qw/DBIx::Class::Schema/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Class::C3::Componentised ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use DBIx::Class::Schema::PgLog::Structure;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 __PACKAGE__->mk_classdata('pg_log_connection');
13 3 __PACKAGE__->mk_classdata('pg_log_schema');
14 3 __PACKAGE__->mk_classdata('pg_log_schema_template');
15 3 __PACKAGE__->mk_classdata('pg_log_storage_type');
16  
17 =head1 NAME
18  
19 DBIx::Class::Schema::PgLog - Schema PgLog Module
20  
21 =head1 VERSION
22  
23 Version 0.03
24  
25 =cut
26  
27 3 our $VERSION = '0.03';
28  
29  
30 =head1 SYNOPSIS
31  
32 Perhaps a little code snippet.
33  
34 use DBIx::Class::Schema::PgLog;
35  
36 my $foo = DBIx::Class::Schema::PgLog->new();
37 ...
38  
39 =head1 DBIx::Class OVERRIDDEN METHODS
40  
41 =head2 connection
42  
43 Overrides the DBIx::Class connection method to create an PgLog schema.
44  
45 =cut
46  
47 0 ▶sub connection {
Subroutine connection: not called CC=4 SCAR=30.0
Pod documented
48 0 my $self = shift;
49  
50 0 my $schema = $self->next::method(@_);
51  
52 0 ▶ my $pg_log_schema = ( ref $self || $self )
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
53 ->find_or_create_pg_log_schema_template->clone;
54  
55 0 ▶ if ( $self->pg_log_connection ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pg_log_connection) { } 0 0 0
56 0 ▶ $pg_log_schema->storage_type( $self->pg_log_storage_type )
Branch: 1 branch
BranchTrueFalseTotal
if $self->pg_log_storage_type 0 0 0
57 if $self->pg_log_storage_type;
58 0 $pg_log_schema->connection( @{ $self->pg_log_connection } );
59 }
60 else {
61 0 $pg_log_schema->storage( $schema->storage );
62 }
63  
64 0 $self->pg_log_schema($pg_log_schema);
65  
66 0 $self->pg_log_schema->storage->disconnect();
67  
68 0 return $schema;
69 }
70  
71 =head2 txn_do
72  
73 Wraps the DBIx::Class txn_do method with a new logset whenever required.
74  
75 =cut
76 0 ▶sub txn_do {
Subroutine txn_do: not called CC=4 SCAR=30.0
Pod documented
77 0 my ( $self, $user_code, @args ) = @_;
78  
79 0 my $pg_log_schema = $self->pg_log_schema;
80  
81 0 my $code = $user_code;
82  
83 0 my $logset_data = $args[0];
84  
85 0 my $current_logset = $pg_log_schema->_current_logset;
86 0 ▶ if ( !$current_logset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current_logset) 0 0 0
87 0 my $current_logset_ref
88 = $pg_log_schema->_current_logset_container;
89  
90 0 ▶ unless ($current_logset_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current_logset_ref) 0 0 0
91 0 $current_logset_ref = {};
92 0 $pg_log_schema->_current_logset_container(
93 $current_logset_ref);
94 }
95  
96 0 ▶ $code = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 # creates local variables in the transaction scope to store
98 # the changset args, and the logset id
99 0 local $current_logset_ref->{args} = $args[0];
100 0 local $current_logset_ref->{logset} = '';
101 0 $user_code->(@_);
102 0 };
103 }
104  
105 0 ▶ if ( $pg_log_schema->storage != $self->storage ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pg_log_schema->storage != $self->storage) 0 0 0
106 0 my $inner_code = $code;
107 0 ▶ $code = sub { $pg_log_schema->txn_do( $inner_code, @_ ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 }
109  
110 0 return $self->next::method( $code, @args );
111 }
112  
113 =head1 HELPER METHODS
114  
115 =head2 pg_log_sources
116  
117 returns the list of sourcenames which have DBIx::Class::PgLog loaded
118  
119 =cut
120  
121 0 ▶sub pg_log_sources{
Subroutine pg_log_sources: not called CC=1 SCAR=6.9
Pod documented
122 0 my $self = shift;
123 0 grep { $self->class($_)->isa("DBIx::Class::PgLog") }
124 $self->sources;
125 }
126  
127 =head2 pg_log_source
128  
129 =over
130  
131 =item Arguments: $source_name
132  
133 =back
134  
135 Like L<DBIx::Class::Schema/source>, but returns 0 if the resulting source does not have
136 PgLog loaded
137  
138 =cut
139  
140 0 ▶sub pg_log_source {
Subroutine pg_log_source: not called CC=3 SCAR=24.8
Pod documented
141 0 my $source = shift->source(@_);
142  
143 0 ▶ return $source if $source && $source->isa("DBIx::Class::PgLog");
Branch: 1 branch
BranchTrueFalseTotal
if $source and $source->isa("DBIx::Class::PgLog") 0 0 0
Condition0%0/3
$source and $source->isa("DBIx::Class::PgLog")
!ll&&!rl&&r
000
MC/DC0%0/2
$source and $source->isa("DBIx::Class::PgLog")
$source $source->isa("DBIx::Class::PgLog")
Truth table0%0/3
A and B
A= $sourceB= $source->isa("DBIx::Class::PgLog")
ABresult
0X0
100
111
144 0 return 0;
145 }
146  
147 =head2 find_or_create_pg_log_schema_template
148  
149 Finds or creates a new schema object using the PgLog tables.
150  
151 =cut
152 0 ▶sub find_or_create_pg_log_schema_template {
Subroutine find_or_create_pg_log_schema_template: not called CC=4 SCAR=30.0
Pod documented
153 0 my $self = shift;
154  
155 0 my $schema = $self->pg_log_schema_template;
156  
157 0 ▶ return $schema if $schema;
Branch: 1 branch
BranchTrueFalseTotal
if $schema 0 0 0
158  
159 0 ▶ my $c = blessed($self) || $self;
Condition0%0/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table0%0/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
160  
161 0 my $class = "${c}::_PGLOG";
162  
163 0 Class::C3::Componentised->inject_base( $class,
164 'DBIx::Class::Schema::PgLog::Structure' );
165  
166 0 $schema = $self->pg_log_schema_template(
167 $class->compose_namespace( $c . '::PgLog' ) );
168  
169 0 my $prefix = 'PgLog';
170 0 foreach my $pg_log_table (
171 qw< Log LogSet>)
172 {
173 0 my $class = blessed($schema) . "::$pg_log_table";
174  
175 0 Class::C3::Componentised->inject_base( $class,
176 "DBIx::Class::Schema::PgLog::Structure::$pg_log_table" );
177  
178 0 $schema->register_class( $prefix . $pg_log_table, $class );
179  
180 }
181  
182 0 return $schema;
183 }
184  
185 =head1 AUTHOR
186  
187 Sheeju Alex, C<< <sheeju at exceleron.com> >>
188  
189 =head1 BUGS
190  
191 Please report any bugs or feature requests to C<bug-dbix-class-pglog at rt.cpan.org>, or through
192 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-PgLog>. I will be notified, and then you'll
193 automatically be notified of progress on your bug as I make changes.
194  
195  
196  
197  
198 =head1 SUPPORT
199  
200 You can find documentation for this module with the perldoc command.
201  
202 perldoc DBIx::Class::Schema::PgLog
203  
204  
205 You can also look for information at:
206  
207 =over 4
208  
209 =item * RT: CPAN's request tracker (report bugs here)
210  
211 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-PgLog>
212  
213 =item * AnnoCPAN: Annotated CPAN documentation
214  
215 L<http://annocpan.org/dist/DBIx-Class-PgLog>
216  
217 =item * CPAN Ratings
218  
219 L<http://cpanratings.perl.org/d/DBIx-Class-PgLog>
220  
221 =item * Search CPAN
222  
223 L<http://search.cpan.org/dist/DBIx-Class-PgLog/>
224  
225 =back
226  
227  
228 =head1 ACKNOWLEDGEMENTS
229  
230  
231 =head1 LICENSE AND COPYRIGHT
232  
233 Copyright 2013 Sheeju Alex.
234  
235 This program is free software; you can redistribute it and/or modify it
236 under the terms of the the Artistic License (2.0). You may obtain a
237 copy of the full license at:
238  
239 L<http://www.perlfoundation.org/artistic_license_2_0>
240  
241 Any use, modification, and distribution of the Standard or Modified
242 Versions is governed by this Artistic License. By using, modifying or
243 distributing the Package, you accept this license. Do not use, modify,
244 or distribute the Package, if you do not accept this license.
245  
246 If your Modified Version has been derived from a Modified Version made
247 by someone other than you, you are nevertheless required to ensure that
248 your Modified Version complies with the requirements of this license.
249  
250 This license does not grant you the right to use any trademark, service
251 mark, tradename, or logo of the Copyright Holder.
252  
253 This license includes the non-exclusive, worldwide, free-of-charge
254 patent license to make, have made, use, offer to sell, sell, import and
255 otherwise transfer the Package with respect to any patent claims
256 licensable by the Copyright Holder that are necessarily infringed by the
257 Package. If you institute patent litigation (including a cross-claim or
258 counterclaim) against any party alleging that the Package constitutes
259 direct or contributory patent infringement, then this Artistic License
260 to you shall terminate on the date that such litigation is filed.
261  
262 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
263 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
264 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
265 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
266 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
267 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
268 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
269 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270  
271  
272 =cut
273  
274 3 1; # End of DBIx::Class::Schema::PgLog
« PgLog.pm ↑ Summary ResultSet/PgLog.pm »