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