| 1 | package SQL::Statement::Util; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||
| 5 | # This module is copyright (c), 2001,2005 by Jeff Zucker. | ||||||||||||||||||||||||||||||||
| 6 | # This module is copyright (c), 2007-2020 by Jens Rehsack. | ||||||||||||||||||||||||||||||||
| 7 | # All rights reserved. | ||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||
| 9 | # It may be freely distributed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||
| 10 | # See below for help and copyright information (search for SYNOPSIS). | ||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||
| 12 | ###################################################################### | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 16 | ▶ | use warnings FATAL => "all"; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 16 | $VERSION = '1.414'; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | sub type | ||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 22 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | return 'function' if $self->isa('SQL::Statement::Util::Function'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | return 'column' if $self->isa('SQL::Statement::Util::Column'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | package SQL::Statement::Util::Column; | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 16 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | 16 | @ISA = qw(SQL::Statement::Util); | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 16 | ▶ | use Params::Util qw(_ARRAY _HASH0 _STRING); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | sub new | ||||||||||||||||||||||||||||||||
| 35 | 1127 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 36 | 1127 | my ( $class, $col_name, $table_name, $term, $display_name, $full_orig_name, $coldef ) = @_; | |||||||||||||||||||||||||||||||
| 37 | 1127 | ▶ | $display_name ||= $col_name; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$display_name ||= $col_name
MC/DC0%0/2
$display_name ||= $col_name
$display_name
$col_name
Truth table66%2/3
A ||= B
A= $display_nameB= $col_name
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 1127 | ▶ | if ( $col_name && ( $col_name =~ m/^((?:"[^"]+")|(?:[^.]*))\.(.*)$/ ) ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$col_name and $col_name =~ /^((?:"[^"]+")|(?:[^.]*))\.(.*)$/
MC/DC50%1/2
$col_name and $col_name =~ /^((?:"[^"]+")|(?:[^.]*))\.(.*)$/
$col_name
$col_name =~ /^((?:"[^"]+")|(?:[^.]*))\.(.*)$/
Truth table66%2/3
A and B
A= $col_nameB= $col_name =~ /^((?:"[^"]+")|(?:[^.]*))\.(.*)$/
| |||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||
| 41 | 20 | $table_name = $1; | |||||||||||||||||||||||||||||||
| 42 | 20 | $col_name = $2; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | elsif ( defined( _ARRAY($table_name) ) && ( scalar( @{$table_name} ) == 1 ) ) | ||||||||||||||||||||||||||||||
|
Condition33%1/3
defined &_ARRAY($table_name) and scalar @{$table_name;} == 1
MC/DC0%0/2
defined &_ARRAY($table_name) and scalar @{$table_name;} == 1
defined &_ARRAY($table_name)
scalar @{$table_name;} == 1
Truth table33%1/3
A and B
A= defined &_ARRAY($table_name)B= scalar @{$table_name;} == 1
| |||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||
| 46 | 0 | $table_name = $table_name->[0]; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1127 | my %instance = ( | |||||||||||||||||||||||||||||||
| 50 | name => $col_name, | ||||||||||||||||||||||||||||||||
| 51 | table => $table_name, | ||||||||||||||||||||||||||||||||
| 52 | display_name => $display_name, | ||||||||||||||||||||||||||||||||
| 53 | term => $term, | ||||||||||||||||||||||||||||||||
| 54 | full_orig_name => $full_orig_name, | ||||||||||||||||||||||||||||||||
| 55 | coldef => $coldef, | ||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 1127 | my $self = bless( \%instance, $class ); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 1127 | return $self; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 21262 | ▶ | sub value($) { $_[0]->{term}->value( $_[1] ); } | ||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub term() { $_[0]->{term} } | ||||||||||||||||||||||||||||||
|
Subroutine
term: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 65 | 13748 | ▶ | sub display_name() { $_[0]->{display_name} } | ||||||||||||||||||||||||||||||
|
Subroutine
display_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub full_orig_name() { $_[0]->{full_orig_name} } | ||||||||||||||||||||||||||||||
|
Subroutine
full_orig_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 67 | 13283 | ▶ | sub name() { $_[0]->{name} } | ||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 68 | 496 | ▶ | sub table() { $_[0]->{table} } | ||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub coldef() { $_[0]->{coldef} } | ||||||||||||||||||||||||||||||
|
Subroutine
coldef: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | package SQL::Statement::Util::Function; | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 16 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 74 | 16 | @ISA = qw(SQL::Statement::Util); | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | sub new | ||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 78 | 2 | my ( $class, $name, $sub_name, $args ) = @_; | |||||||||||||||||||||||||||||||
| 79 | 2 | my ( $pkg, $sub ) = $sub_name =~ /^(.*::)([^:]+$)/; | |||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ( !$sub ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||
| 82 | 1 | $pkg = 'main'; | |||||||||||||||||||||||||||||||
| 83 | 1 | $sub = $sub_name; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | $pkg = 'main' if $pkg eq '::'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 2 | $pkg =~ s/::$//; | |||||||||||||||||||||||||||||||
| 87 | 2 | my %newfunc = ( | |||||||||||||||||||||||||||||||
| 88 | name => $name, | ||||||||||||||||||||||||||||||||
| 89 | sub_name => $sub, | ||||||||||||||||||||||||||||||||
| 90 | pkg_name => $pkg, | ||||||||||||||||||||||||||||||||
| 91 | args => $args, | ||||||||||||||||||||||||||||||||
| 92 | type => 'function', | ||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||
| 94 | 2 | return bless \%newfunc, $class; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | sub name { shift->{name} } | ||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub pkg_name { shift->{pkg_name} } | ||||||||||||||||||||||||||||||
|
Subroutine
pkg_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | sub sub_name { shift->{sub_name} } | ||||||||||||||||||||||||||||||
|
Subroutine
sub_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub args { shift->{args} } | ||||||||||||||||||||||||||||||
|
Subroutine
args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | sub validate | ||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 103 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 104 | 2 | my $pkg = $self->pkg_name; | |||||||||||||||||||||||||||||||
| 105 | 2 | my $sub = $self->sub_name; | |||||||||||||||||||||||||||||||
| 106 | 2 | $pkg =~ s,::,/,g; | |||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | eval { require "$pkg.pm" } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pkg eq "SQL/Statement/Functions" or $pkg eq "main"
MC/DC50%1/2
$pkg eq "SQL/Statement/Functions" or $pkg eq "main"
$pkg eq "SQL/Statement/Functions"
$pkg eq "main"
Truth table66%2/3
A or B
A= $pkg eq "SQL/Statement/Functions"B= $pkg eq "main"
| |||||||||||||||||||||||||||||||||
| 108 | unless $pkg eq 'SQL/Statement/Functions' | ||||||||||||||||||||||||||||||||
| 109 | or $pkg eq 'main'; | ||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | 2 | $pkg =~ s,/,::,g; | |||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | die "Can't find subroutine $pkg" . "::$sub\n" unless $pkg->can($sub); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 1 | return 1; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | sub run | ||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=1.7
| |||||||||||||||||||||||||||||||||
| 118 | 16 | ▶ | use SQL::Statement::Functions; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||
| 121 | 0 | my $sub = $self->sub_name; | |||||||||||||||||||||||||||||||
| 122 | 0 | my $pkg = $self->pkg_name; | |||||||||||||||||||||||||||||||
| 123 | 0 | return $pkg->$sub(@_); | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 16 | 1; | |||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | =pod | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | SQL::Statement::Util | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | SQL::Statement::Util::Column->new($col_name, $table_name, $term, $display_name) | ||||||||||||||||||||||||||||||||
| 137 | SQL::Statement::Util::AggregatedColumns($col_name, $table_name, $term, $display_name) | ||||||||||||||||||||||||||||||||
| 138 | SQL::Statement::Util::Function($name, $sub_name, $args) | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | This package contains three utility classes to handle deliverable columns. | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =head1 INHERITANCE | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | SQL::Statement::Util::Column | ||||||||||||||||||||||||||||||||
| 147 | ISA SQL::Statement::Util | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | SQL::Statement::Util::AggregatedColumns | ||||||||||||||||||||||||||||||||
| 150 | ISA SQL::Statement::Util::Column | ||||||||||||||||||||||||||||||||
| 151 | ISA SQL::Statement::Util | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | SQL::Statement::Util::Function | ||||||||||||||||||||||||||||||||
| 154 | ISA SQL::Statement::Util | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | =begin undocumented | ||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | =head2 type | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | Returns the type of the SQL::Statement::Util instance. | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | =end undocumented | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | =head1 AUTHOR & COPYRIGHT | ||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | This module is | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | copyright (c) 2001,2005 by Jeff Zucker and | ||||||||||||||||||||||||||||||||
| 171 | copyright (c) 2007-2020 by Jens Rehsack. | ||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | All rights reserved. | ||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | The module may be freely distributed under the same terms as | ||||||||||||||||||||||||||||||||
| 176 | Perl itself using either the "GPL License" or the "Artistic | ||||||||||||||||||||||||||||||||
| 177 | License" as specified in the Perl README file. | ||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | Jeff can be reached at: jzuckerATcpan.org | ||||||||||||||||||||||||||||||||
| 180 | Jens can be reached at: rehsackATcpan.org or via dbi-devATperl.org | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||