Roles/SQLAbstract.pm

filter: Statementstmt 68.5% 24 / 35 Branchbran 33.3% 2 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 66.6% 4 / 6 totaltotal 64.9% 37 / 57 CC 4 SCAR 8.1
CC
4
Cov
63%
select
6.0
STORE
2.0
abstract
2.0
CRAP 2.2
« Roles/Hook.pm ↑ Summary Roles/Transaction.pm »
1 # $Id: SQLAbstract.pm,v 1.2 2005/11/29 11:55:01 dk Exp $
2  
3 package DBIx::Roles::SQLAbstract;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use vars qw(%defaults $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use SQL::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $VERSION = '1.00';
9  
10 # SQL::Abstract parameters to new()
11 1 %defaults = (
12 case => 'textbook',
13 cmp => '=',
14 logic => 'or',
15 convert => 0,
16 bindtype => 'normal',
17 quote_char => '',
18 name_sep => undef,
19 );
20  
21 sub initialize
22 3 ▶{
Subroutine initialize: called CC=1 SCAR=0.0
Pod undocumented
23 3 return [], \%defaults, qw(insert select update delete);
24 }
25  
26 sub insert
27 1 ▶{
Subroutine insert: called CC=1 SCAR=0.0
Pod documented
28 1 my ( $self, $sql) = @_;
29 1 my ( $query, @bindval) = abstract('insert', @_);
30 1 $self-> do( $query, {}, @bindval);
31 }
32  
33 sub select
34 0 ▶{
Subroutine select: not called CC=2 SCAR=17.9
Pod documented
35 0 my ( $self, $sql) = @_;
36 0 my ( $query, @bindval) = abstract('select', @_);
37 0 my $sth = $self-> prepare( $query);
38 0 ▶ $sth-> execute( @bindval) if $sth;
Branch: 1 branch
BranchTrueFalseTotal
if $sth 0 0 0
39 0 return $sth;
40 }
41  
42 sub update
43 0 ▶{
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
44 0 my ( $self, $sql) = @_;
45 0 my ( $query, @bindval) = abstract('update', @_);
46 0 $self-> do( $query, {}, @bindval);
47 }
48  
49 sub delete
50 0 ▶{
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
51 0 my ( $self, $sql) = @_;
52 0 my ( $query, @bindval) = abstract('delete', @_);
53 0 $self-> do( $query, {}, @bindval);
54 }
55  
56 sub abstract
57 1 ▶{
Subroutine abstract: called CC=2 SCAR=7.0
Pod undocumented
58 1 my ( $method, $self, $sql, @params) = @_;
59  
60 # auto-instantiate, if any
61 $sql->[0] = SQL::Abstract-> new(
62 1 ▶ map { $_ => $self->{attr}->{$_} } keys %defaults)
Branch: 1 branch
BranchTrueFalseTotal
unless $sql->[0] 1 0 1
63 unless $sql->[0];
64 1 $sql = $sql->[0];
65  
66 1 return $sql-> $method( @params);
67 }
68  
69 sub STORE
70 17 ▶{
Subroutine STORE: called CC=2 SCAR=7.1
71 17 my ( $self, $sql, $key, $val) = @_;
72  
73 # delete the SQL::Abstract object if settings have changed
74 17 ▶ undef $sql->[0] if exists $defaults{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $DBIx::Roles::SQLAbstract::defaults{$key} 0 17 17
75  
76 17 return $self-> super( $key, $val);
77 }
78  
79 1 1;
80  
81 __DATA__
« Roles/Hook.pm ↑ Summary Roles/Transaction.pm »