Database/Table.pm

filter: Statementstmt 88.1% 67 / 76 Branchbran 79.1% 19 / 24 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 5 totaltotal 77.7% 108 / 139 SCAR 28.5
CC
16
Cov
83%
_build_sth
9.4
select
3.2
where
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_001';
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 2 ▶ my ( $self ) = ( shift );
Subroutine _clone: called CC=1 SCAR=0.0
22
23 2 my %args = ( %$self, @_ );
24 2 delete $args{'_linq_iterator'};
25 2 ref( $self )->new( %args );
26 }
27  
28 sub select {
29 1 ▶ my ( $self ) = ( shift );
Subroutine select: called CC=3 SCAR=11.8
Pod undocumented
30 1 my $selection = LINQ::Util::Internal::assert_code( @_ );
31
32 1 ▶ if ( !$self->sql_select ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->sql_select) 1 0 1
33 1 my $columns = LINQ::Database::Util::selection_to_sql( $selection );
34 1 ▶ return $self->_clone( sql_select => $selection ) if $columns;
Branch: 1 branch
BranchTrueFalseTotal
if $columns 1 0 1
35 }
36
37 0 $self->LINQ::Collection::select( $selection );
38 }
39  
40 sub where {
41 1 ▶ my ( $self ) = ( shift );
Subroutine where: called CC=3 SCAR=11.8
Pod undocumented
42 1 my $assertion = LINQ::Util::Internal::assert_code( @_ );
43
44 1 ▶ if ( !$self->sql_where ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->sql_where) 1 0 1
45 1 my $filter = LINQ::Database::Util::assertion_to_sql( $assertion );
46 1 ▶ return $self->_clone( sql_where => $filter ) if $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $filter 1 0 1
47 }
48
49 0 $self->LINQ::Collection::where( $assertion );
50 }
51  
52 sub to_iterator {
53 0 ▶ my ( $self ) = ( shift );
Subroutine to_iterator: not called CC=1 SCAR=6.9
Pod undocumented
54 0 $self->_linq_iterator->to_iterator;
55 }
56  
57 sub to_list {
58 4 ▶ my ( $self ) = ( shift );
Subroutine to_list: called CC=1 SCAR=0.0
Pod undocumented
59 4 $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 4 ▶ my ( $self ) = ( shift );
Subroutine _linq_iterator: called CC=2 SCAR=7.1
69 4 ▶ $self->{_linq_iterator} ||= $self->_build_linq_iterator;
Condition66%2/3
$self->{"_linq_iterator"} ||= $self->_build_linq_iterator
l!l&&r!l&&!r
130
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 3 ▶ my ( $self ) = ( shift );
Subroutine _build_linq_iterator: called CC=2 SCAR=6.9
74
75 3 my $sth = $self->_build_sth;
76 my $map = defined( $self->sql_select )
77 ? $self->sql_select
78 3 ▶ : sub { Object::Adhoc::object( $_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_select ? : 1 2 3
79 3 my $started = 0;
80
81 LINQ::LINQ( sub {
82 16 ▶ if ( not $started ) {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 3 13 16
83 3 $sth->execute;
84 3 ++$started;
85 }
86 16 ▶ local $_ = $sth->fetchrow_hashref or return LINQ::END;
Branch: 1 branch
BranchTrueFalseTotal
local $_ = $sth->fetchrow_hashref or return &LINQ::END() 3 13 16
87 13 return $map->( $_ );
88 3 } );
89 }
90  
91 sub _build_sth {
92 3 ▶ my ( $self ) = ( shift );
Subroutine _build_sth: called CC=8 SCAR=22.4
93
94 3 ▶ my $sql_select = defined($self->sql_select) ? $self->sql_select : '*';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_select ? : 1 2 3
95 3 ▶ if ( ref( $sql_select ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sql_select) 1 2 3
96 $sql_select = LINQ::Database::Util::selection_to_sql(
97 $sql_select,
98 2 ▶ sub { $self->database->quote_identifier( @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 1 ▶ ) || '*';
Condition50%1/2
LINQ::Database::Util::selection_to_sql($sql_select, sub { || '*'
l!l
10
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 3 ▶ my $sql_where = defined($self->sql_where) ? $self->sql_where : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->sql_where ? : 1 2 3
103 3 ▶ if ( ref( $sql_where ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sql_where) 0 3 3
104 $sql_where = LINQ::Database::Util::selection_to_sql(
105 $sql_where,
106 0 ▶ sub { $self->database->quote_identifier( @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 0 ▶ sub { $self->database->quote( @_ ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 ▶ ) || '';
Condition0%0/2
LINQ::Database::Util::selection_to_sql($sql_where, sub { || ''
l!l
00
MC/DC0%0/1
LINQ::Database::Util::selection_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } ) || ''
LINQ::Database::Util::selection_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } )
Truth table0%0/2
A
A= LINQ::Database::Util::selection_to_sql($sql_where, sub { $self->database->quote_identifier(@_); } , sub { $self->database->quote(@_); } )
Aresult
11
00
109 }
110
111 3 ▶ $self->database->prepare( sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$sql_where ? : 1 2 3
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 »