File Coverage

blib/lib/SQL/Statement/Util.pm
Criterion Covered Total %
statement 58 68 85.2
branch 14 18 77.7
condition 7 12 58.3
subroutine 18 23 78.2
pod 1 1 100.0
total 98 122 80.3


line stmt bran cond sub pod time code
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-2017 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     16   65 use strict;
  16         18  
  16         493  
15 16     16   56 use warnings FATAL => "all";
  16         21  
  16         637  
16              
17 16     16   63 use vars qw($VERSION);
  16         467  
  16         1583  
18             $VERSION = '1.412';
19              
20             sub type
21             {
22 2     2 1 13 my ($self) = @_;
23 2 100       20 return 'function' if $self->isa('SQL::Statement::Util::Function');
24 1 50       7 return 'column' if $self->isa('SQL::Statement::Util::Column');
25             }
26              
27             package SQL::Statement::Util::Column;
28              
29 16     16   70 use vars qw(@ISA);
  16         18  
  16         692  
30             @ISA = qw(SQL::Statement::Util);
31              
32 16     16   65 use Params::Util qw(_ARRAY _HASH0 _STRING);
  16         20  
  16         5157  
33              
34             sub new
35             {
36 1127     1127   1514 my ( $class, $col_name, $table_name, $term, $display_name, $full_orig_name, $coldef ) = @_;
37 1127   66     1736 $display_name ||= $col_name;
38              
39 1127 100 66     5860 if ( $col_name && ( $col_name =~ m/^((?:"[^"]+")|(?:[^.]*))\.(.*)$/ ) )
    50 33        
40             {
41 20         41 $table_name = $1;
42 20         30 $col_name = $2;
43             }
44 0         0 elsif ( defined( _ARRAY($table_name) ) && ( scalar( @{$table_name} ) == 1 ) )
45             {
46 0         0 $table_name = $table_name->[0];
47             }
48              
49 1127         3598 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         1285 my $self = bless( \%instance, $class );
59              
60 1127         2088 return $self;
61             }
62              
63 21262     21262   30214 sub value($) { $_[0]->{term}->value( $_[1] ); }
64 0     0   0 sub term() { $_[0]->{term} }
65 13748     13748   26649 sub display_name() { $_[0]->{display_name} }
66 0     0   0 sub full_orig_name() { $_[0]->{full_orig_name} }
67 13283     13283   24634 sub name() { $_[0]->{name} }
68 496     496   967 sub table() { $_[0]->{table} }
69 0     0   0 sub coldef() { $_[0]->{coldef} }
70              
71             package SQL::Statement::Util::Function;
72              
73 16     16   75 use vars qw(@ISA);
  16         19  
  16         4997  
74             @ISA = qw(SQL::Statement::Util);
75              
76             sub new
77             {
78 2     2   340 my ( $class, $name, $sub_name, $args ) = @_;
79 2         8 my ( $pkg, $sub ) = $sub_name =~ /^(.*::)([^:]+$)/;
80 2 100       5 if ( !$sub )
81             {
82 1         2 $pkg = 'main';
83 1         2 $sub = $sub_name;
84             }
85 2 50       5 $pkg = 'main' if $pkg eq '::';
86 2         5 $pkg =~ s/::$//;
87 2         9 my %newfunc = (
88             name => $name,
89             sub_name => $sub,
90             pkg_name => $pkg,
91             args => $args,
92             type => 'function',
93             );
94 2         5 return bless \%newfunc, $class;
95             }
96 1     1   5 sub name { shift->{name} }
97 2     2   3 sub pkg_name { shift->{pkg_name} }
98 2     2   4 sub sub_name { shift->{sub_name} }
99 0     0   0 sub args { shift->{args} }
100              
101             sub validate
102             {
103 2     2   9 my ($self) = @_;
104 2         5 my $pkg = $self->pkg_name;
105 2         4 my $sub = $self->sub_name;
106 2         4 $pkg =~ s,::,/,g;
107 2 100 66     14 eval { require "$pkg.pm" }
  1         8  
108             unless $pkg eq 'SQL/Statement/Functions'
109             or $pkg eq 'main';
110 2 50       4 die $@ if $@;
111 2         5 $pkg =~ s,/,::,g;
112 2 100       20 die "Can't find subroutine $pkg" . "::$sub\n" unless $pkg->can($sub);
113 1         4 return 1;
114             }
115              
116             sub run
117             {
118 16     16   85 use SQL::Statement::Functions;
  16         19  
  16         1073  
119              
120 0     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             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-2017 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