| 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
| |||||||||||||||||||||||||||||
| 33 | 3 | my $columns = LINQ::Database::Util::selection_to_sql( $selection ); | |||||||||||||||||||||||||||
| 34 | 3 | ▶ | return $self->_clone( sql_select => $selection ) if $columns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $self->sql_where or defined $self->sql_select
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
| |||||||||||||||||||||||||||||
| 45 | 3 | my $filter = LINQ::Database::Util::assertion_to_sql( $assertion ); | |||||||||||||||||||||||||||
| 46 | 3 | ▶ | return $self->_clone( sql_where => $assertion ) if $filter; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | 6 | $sth->execute; | |||||||||||||||||||||||||||
| 84 | 6 | ++$started; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 32 | ▶ | local $_ = $sth->fetchrow_hashref or return LINQ::END; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | 6 | ▶ | if ( ref( $sql_select ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 { || '*'
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(@_);
}
)
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 6 | ▶ | my $sql_where = defined($self->sql_where) ? $self->sql_where : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 6 | ▶ | if ( ref( $sql_where ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 { || ''
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(@_);
}
)
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6 | ▶ | $self->database->prepare( sprintf( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||