Database/Table.pm

filter: Statementstmt 96.0% 73 / 76 Branchbran 91.6% 22 / 24 Conditioncond 60.0% 6 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 95.6% 22 / 23 Podpod 0.0% 0 / 5 totaltotal 86.1% 124 / 144 SCAR 28.4
CC
17
Cov
92%
_build_sth
8.0
where
4.0
select
3.2
CRAP 17.2
« Database/Util.pm ↑ Summary Database.pm »
1 1 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package LINQ::Database::Table;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.000_002';
9  
10 1 ▶use Class::Tiny qw( database name sql_select sql_where );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use LINQ ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use LINQ::Util::Internal ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use LINQ::Database::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Object::Adhoc ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Role::Tiny::With ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 Role::Tiny::With::with 'LINQ::Collection';
19  
20 sub _clone {
21 5 ▶ my ( $self ) = ( shift );
Subroutine _clone: called CC=1 SCAR=0.0
22
23 5 my %args = ( %$self, @_ );
24 5 delete $args{'_linq_iterator'};
25 5 ref( $self )->new( %args );
26 }
27  
28 sub select {
29 3 ▶ my ( $self ) = ( shift );
Subroutine select: called CC=3 SCAR=11.8
Pod undocumented
30 3 my $selection = LINQ::Util::Internal::assert_code( @_ );
31
32 3 ▶ if ( ! defined($self->sql_select) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->sql_select) 3 0 3
33 3 my $columns = LINQ::Database::Util::selection_to_sql( $selection );
34 3 ▶ return $self->_clone( sql_select => $selection ) if $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $columns 3 0 3
35 }
36
37 0 $self->LINQ::Collection::select( $selection );
38 }
39  
40 sub where {
41 4 ▶ my ( $self ) = ( shift );
Subroutine where: called CC=4 SCAR=13.9
Pod undocumented
42 4 my $assertion = LINQ::Util::Internal::assert_code( @_ );
43
44 4 ▶ if ( ! defined($self->sql_where) and ! defined($self->sql_select) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->sql_where or defined $self->sql_select) 3 1 4
Condition66%2/3
defined $self->sql_where or defined $self->sql_select
l!l&&r!l&&!r
013
MC/DC50%1/2
defined $self->sql_where or defined $self->sql_select
defined $self->sql_where defined $self->sql_select
Truth table66%2/3
A or B
A= defined $self->sql_whereB= defined $self->sql_select
ABresult
1X1
011
000
45 3 my $filter = LINQ::Database::Util::assertion_to_sql( $assertion );
46 3 ▶ return $self->_clone( sql_where => $assertion ) if $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $filter 2 1 3
47 }
48
49 2 $self->LINQ::Collection::where( $assertion );
50 }
51  
52 sub to_iterator {
53 2 ▶ my ( $self ) = ( shift );
Subroutine to_iterator: called CC=1 SCAR=0.0
Pod undocumented
54 2 $self->_linq_iterator->to_iterator;
55 }
56  
57 sub to_list {
58 6 ▶ my ( $self ) = ( shift );
Subroutine to_list: called CC=1 SCAR=0.0
Pod undocumented
59 6 $self->_linq_iterator->to_list;
60 }
61  
62 sub to_array {
63 0 ▶ my ( $self ) = ( shift );
Subroutine to_array: not called CC=1 SCAR=6.9
Pod undocumented
64 0 $self->_linq_iterator->to_array;
65 }
66  
67 sub _linq_iterator {
68 8 ▶ my ( $self ) = ( shift );
Subroutine _linq_iterator: called CC=2 SCAR=7.1
69 8 ▶ $self->{_linq_iterator} ||= $self->_build_linq_iterator;
Condition66%2/3
$self->{"_linq_iterator"} ||= $self->_build_linq_iterator
l!l&&r!l&&!r
260
MC/DC0%0/2
$self->{"_linq_iterator"} ||= $self->_build_linq_iterator
$self->{"_linq_iterator"} $self->_build_linq_iterator
Truth table66%2/3
A ||= B
A= $self->{"_linq_iterator"}B= $self->_build_linq_iterator
ABresult
1X1
011
000
70 }
71  
72 sub _build_linq_iterator {
73 6 ▶ my ( $self ) = ( shift );
Subroutine _build_linq_iterator: called CC=2 SCAR=6.9
74
75 6 my $sth = $self->_build_sth;
76 my $map = defined( $self->sql_select )
77 ? $self->sql_select
78 6 ▶ : sub { Object::Adhoc::object( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_select ? : 3 3 6
79 6 my $started = 0;
80
81 LINQ::LINQ( sub {
82 32 ▶ if ( not $started ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 6 26 32
83 6 $sth->execute;
84 6 ++$started;
85 }
86 32 ▶ local $_ = $sth->fetchrow_hashref or return LINQ::END;
Branch: 1 branch
BranchTrueFalseTotal
local $_ = $sth->fetchrow_hashref or return &LINQ::END() 6 26 32
87 26 return $map->( $_ );
88 6 } );
89 }
90  
91 sub _build_sth {
92 6 ▶ my ( $self ) = ( shift );
Subroutine _build_sth: called CC=8 SCAR=20.8
93
94 6 ▶ my $sql_select = defined($self->sql_select) ? $self->sql_select : '*';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_select ? : 3 3 6
95 6 ▶ if ( ref( $sql_select ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sql_select) 3 3 6
96 $sql_select = LINQ::Database::Util::selection_to_sql(
97 $sql_select,
98 4 ▶ sub { $self->database->quote_identifier( @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 3 ▶ ) || '*';
Condition50%1/2
LINQ::Database::Util::selection_to_sql($sql_select, sub { || '*'
l!l
30
MC/DC0%0/1
LINQ::Database::Util::selection_to_sql($sql_select, sub { $self->database->quote_identifier(@_); } ) || '*'
LINQ::Database::Util::selection_to_sql($sql_select, sub { $self->database->quote_identifier(@_); } )
Truth table50%1/2
A
A= LINQ::Database::Util::selection_to_sql($sql_select, sub { $self->database->quote_identifier(@_); } )
Aresult
11
00
100 }
101
102 6 ▶ my $sql_where = defined($self->sql_where) ? $self->sql_where : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_where ? : 2 4 6
103 6 ▶ if ( ref( $sql_where ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sql_where) 2 4 6
104 $sql_where = LINQ::Database::Util::assertion_to_sql(
105 $sql_where,
106 2 ▶ sub { $self->database->quote_identifier( @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
107 2 ▶ sub { $self->database->quote( @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
108 2 ▶ ) || '';
Condition50%1/2
LINQ::Database::Util::assertion_to_sql($sql_where, sub { || ''
l!l
20
MC/DC0%0/1
LINQ::Database::Util::assertion_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } ) || ''
LINQ::Database::Util::assertion_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } )
Truth table50%1/2
A
A= LINQ::Database::Util::assertion_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } )
Aresult
11
00
109 }
110
111 6 ▶ $self->database->prepare( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$sql_where ? : 2 4 6
112 'SELECT %s FROM %s%s',
113 $sql_select,
114 $self->name,
115 ( $sql_where ? " WHERE $sql_where" : $sql_where ),
116 ) );
117 }
118  
119 1 1;
« Database/Util.pm ↑ Summary Database.pm »