| 1 | package SQL::Statement::Term; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | ###################################################################### | ||||||||||||||
| 4 | # | ||||||||||||||
| 5 | # This module is copyright (c), 2009-2020 by Jens Rehsack. | ||||||||||||||
| 6 | # All rights reserved. | ||||||||||||||
| 7 | # | ||||||||||||||
| 8 | # It may be freely distributed under the same terms as Perl itself. | ||||||||||||||
| 9 | # See below for help and copyright information (search for SYNOPSIS). | ||||||||||||||
| 10 | # | ||||||||||||||
| 11 | ###################################################################### | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 16 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 16 | ▶ | use warnings FATAL => "all"; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 16 | our $VERSION = '1.414'; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 16 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 16 | ▶ | use Carp (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | |||||||||||||||
| 21 | =pod | ||||||||||||||
| 22 | |||||||||||||||
| 23 | =head1 NAME | ||||||||||||||
| 24 | |||||||||||||||
| 25 | SQL::Statement::Term - base class for all terms | ||||||||||||||
| 26 | |||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||
| 28 | |||||||||||||||
| 29 | # create a term with an SQL::Statement object as owner | ||||||||||||||
| 30 | my $term = SQL::Statement::Term->new( $owner ); | ||||||||||||||
| 31 | # access the value of that term | ||||||||||||||
| 32 | $term->value( $eval ); | ||||||||||||||
| 33 | |||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||
| 35 | |||||||||||||||
| 36 | SQL::Statement::Term is an abstract base class providing the interface | ||||||||||||||
| 37 | for all terms. | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =head1 INHERITANCE | ||||||||||||||
| 40 | |||||||||||||||
| 41 | SQL::Statement::Term | ||||||||||||||
| 42 | |||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||
| 44 | |||||||||||||||
| 45 | =head2 new | ||||||||||||||
| 46 | |||||||||||||||
| 47 | Instantiates new term and stores a weak reference to the owner. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head2 value | ||||||||||||||
| 50 | |||||||||||||||
| 51 | I<Abstract> method which will return the value of the term. Must be | ||||||||||||||
| 52 | overridden by derived classes. | ||||||||||||||
| 53 | |||||||||||||||
| 54 | =head2 DESTROY | ||||||||||||||
| 55 | |||||||||||||||
| 56 | Destroys the term and undefines the weak reference to the owner. | ||||||||||||||
| 57 | |||||||||||||||
| 58 | =cut | ||||||||||||||
| 59 | |||||||||||||||
| 60 | sub new | ||||||||||||||
| 61 | 2926 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 62 | 2926 | my $class = $_[0]; | |||||||||||||
| 63 | 2926 | my $owner = $_[1]; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 2926 | my $self = bless( { OWNER => $owner }, $class ); | |||||||||||||
| 66 | 2926 | weaken( $self->{OWNER} ); | |||||||||||||
| 67 | |||||||||||||||
| 68 | 2926 | return $self; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | sub DESTROY | ||||||||||||||
| 72 | 2925 | ▶ | { | ||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||
| 73 | 2925 | my $self = $_[0]; | |||||||||||||
| 74 | 2925 | undef $self->{OWNER}; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | sub value($) | ||||||||||||||
| 78 | 0 | ▶ | { | ||||||||||||
|
Subroutine
value: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 79 | 0 | ▶ | Carp::confess( sprintf( q{pure virtual function '%s->value' called}, ref( $_[0] ) || __PACKAGE__ ) ); | ||||||||||||
|
Condition0%0/2
ref $_[0] || __PACKAGE__
MC/DC0%0/1
ref $_[0] || __PACKAGE__
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
| |||||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | package SQL::Statement::ConstantTerm; | ||||||||||||||
| 83 | |||||||||||||||
| 84 | 16 | ▶ | use vars qw(@ISA); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 85 | 16 | @ISA = qw(SQL::Statement::Term); | |||||||||||||
| 86 | |||||||||||||||
| 87 | =pod | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head1 NAME | ||||||||||||||
| 90 | |||||||||||||||
| 91 | SQL::Statement::ConstantTerm - term for constant values | ||||||||||||||
| 92 | |||||||||||||||
| 93 | =head1 SYNOPSIS | ||||||||||||||
| 94 | |||||||||||||||
| 95 | # create a term with an SQL::Statement object as owner | ||||||||||||||
| 96 | my $term = SQL::Statement::ConstantTerm->new( $owner, 'foo' ); | ||||||||||||||
| 97 | # access the value of that term - returns 'foo' | ||||||||||||||
| 98 | $term->value( $eval ); | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||||||
| 101 | |||||||||||||||
| 102 | SQL::Statement::ConstantTerm implements a term which will always return the | ||||||||||||||
| 103 | same constant value. | ||||||||||||||
| 104 | |||||||||||||||
| 105 | =head1 INHERITANCE | ||||||||||||||
| 106 | |||||||||||||||
| 107 | SQL::Statement::ConstantTerm | ||||||||||||||
| 108 | ISA SQL::Statement::Term | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head1 METHODS | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =head2 new | ||||||||||||||
| 113 | |||||||||||||||
| 114 | Instantiates new term and stores the constant to deliver and a weak | ||||||||||||||
| 115 | reference to the owner. | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =head2 value | ||||||||||||||
| 118 | |||||||||||||||
| 119 | Returns the specified constant. | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =cut | ||||||||||||||
| 122 | |||||||||||||||
| 123 | sub new | ||||||||||||||
| 124 | 1173 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||
| 125 | 1173 | my ( $class, $owner, $value ) = @_; | |||||||||||||
| 126 | |||||||||||||||
| 127 | 1173 | my $self = $class->SUPER::new($owner); | |||||||||||||
| 128 | 1173 | $self->{VALUE} = $value; | |||||||||||||
| 129 | |||||||||||||||
| 130 | 1173 | return $self; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 1765 | ▶ | sub value($$) { return $_[0]->{VALUE}; } | ||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
| |||||||||||||||
| 134 | |||||||||||||||
| 135 | package SQL::Statement::ColumnValue; | ||||||||||||||
| 136 | |||||||||||||||
| 137 | 16 | ▶ | use vars qw(@ISA); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 138 | 16 | @ISA = qw(SQL::Statement::Term); | |||||||||||||
| 139 | |||||||||||||||
| 140 | 16 | ▶ | use Carp qw(croak); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 141 | 16 | ▶ | use Params::Util qw(_INSTANCE _ARRAY0 _SCALAR); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 142 | 16 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 143 | |||||||||||||||
| 144 | =pod | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =head1 NAME | ||||||||||||||
| 147 | |||||||||||||||
| 148 | SQL::Statement::ColumnValue - term for column values | ||||||||||||||
| 149 | |||||||||||||||
| 150 | =head1 SYNOPSIS | ||||||||||||||
| 151 | |||||||||||||||
| 152 | # create a term with an SQL::Statement object as owner | ||||||||||||||
| 153 | my $term = SQL::Statement::ColumnValue->new( $owner, 'id' ); | ||||||||||||||
| 154 | # access the value of that term - returns the value of the column 'id' | ||||||||||||||
| 155 | # of the currently active row in $eval | ||||||||||||||
| 156 | $term->value( $eval ); | ||||||||||||||
| 157 | |||||||||||||||
| 158 | =head1 DESCRIPTION | ||||||||||||||
| 159 | |||||||||||||||
| 160 | SQL::Statement::ColumnValue implements a term which will return the specified | ||||||||||||||
| 161 | column of the active row. | ||||||||||||||
| 162 | |||||||||||||||
| 163 | =head1 INHERITANCE | ||||||||||||||
| 164 | |||||||||||||||
| 165 | SQL::Statement::ColumnValue | ||||||||||||||
| 166 | ISA SQL::Statement::Term | ||||||||||||||
| 167 | |||||||||||||||
| 168 | =head1 METHODS | ||||||||||||||
| 169 | |||||||||||||||
| 170 | =head2 new | ||||||||||||||
| 171 | |||||||||||||||
| 172 | Instantiates new term and stores the column name to deliver and a weak | ||||||||||||||
| 173 | reference to the owner. | ||||||||||||||
| 174 | |||||||||||||||
| 175 | =head2 value | ||||||||||||||
| 176 | |||||||||||||||
| 177 | Returns the specified column value. | ||||||||||||||
| 178 | |||||||||||||||
| 179 | =cut | ||||||||||||||
| 180 | |||||||||||||||
| 181 | sub new | ||||||||||||||
| 182 | 1096 | ▶ | { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||
| 183 | 1096 | my ( $class, $owner, $value ) = @_; | |||||||||||||
| 184 | |||||||||||||||
| 185 | 1096 | my $self = $class->SUPER::new($owner); | |||||||||||||
| 186 | 1096 | $self->{VALUE} = $value; | |||||||||||||
| 187 | |||||||||||||||
| 188 | 1096 | return $self; | |||||||||||||
| 189 | } | ||||||||||||||
| 190 | |||||||||||||||
| 191 | sub value($) | ||||||||||||||
| 192 | 18140 | ▶ | { | ||||||||||||
|
Subroutine
value: called CC=9 SCAR=22.3
| |||||||||||||||
| 193 | 18140 | my ( $self, $eval ) = @_; | |||||||||||||
| 194 | 18140 | ▶ | unless ( defined( $self->{TMPVAL} ) ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 195 | { | ||||||||||||||
| 196 | 336 | my ( $tbl, $col ) = $self->{OWNER}->full_qualified_column_name( $self->{VALUE} ); | |||||||||||||
| 197 | 336 | ▶ | defined($tbl) or croak("Can't find table containing column named '$self->{VALUE}'"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | 336 | ▶ | defined($col) or croak("Unknown column: '$self->{VALUE}'"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 199 | 336 | $self->{TMPVAL} = $tbl . $self->{OWNER}->{dlm} . $col; | |||||||||||||
| 200 | 336 | $self->{TABLE_NAME} = $tbl; | |||||||||||||
| 201 | 336 | $self->{COLUMN_NAME} = $col; | |||||||||||||
| 202 | } | ||||||||||||||
| 203 | |||||||||||||||
| 204 | # XXX - can TMPVAL being defined without TABLE_NAME? | ||||||||||||||
| 205 | 18140 | ▶ | unless ( defined( $self->{TABLE_NAME} ) ) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 206 | { | ||||||||||||||
| 207 | 0 | croak( "No table specified: '" . $self->{OWNER}->{original_string} . "'" ); | |||||||||||||
| 208 | } | ||||||||||||||
| 209 | |||||||||||||||
| 210 | # with TempEval: return $eval->column($self->{TABLE_NAME}, $self->{COLUMN_NAME}); | ||||||||||||||
| 211 | 18140 | my $fp; | |||||||||||||
| 212 | defined( $fp = $self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } ) | ||||||||||||||
| 213 | 18140 | ▶ | and return &$fp( $self->{COLUMN_NAME} ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 214 | |||||||||||||||
| 215 | defined( $fp = $self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } ) | ||||||||||||||
| 216 | 1413 | ▶ | and return &$fp( $self->{TMPVAL} ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 217 | |||||||||||||||
| 218 | 394 | ▶ | if ( defined( _INSTANCE( $eval, 'SQL::Eval' ) ) ) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 219 | { | ||||||||||||||
| 220 | $self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } = | ||||||||||||||
| 221 | 224 | $eval->_gen_access_fastpath( $self->{TABLE_NAME} ); | |||||||||||||
| 222 | 224 | return &{ $self->{fastpath}->{ "${eval}." . $self->{TABLE_NAME} } }( $self->{COLUMN_NAME} ); | |||||||||||||
| 223 | } | ||||||||||||||
| 224 | elsif ( defined( _INSTANCE( $eval, 'SQL::Eval::Table' ) ) ) | ||||||||||||||
| 225 | { | ||||||||||||||
| 226 | $self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } = | ||||||||||||||
| 227 | 170 | $eval->_gen_access_fastpath( $self->{TMPVAL} ); | |||||||||||||
| 228 | 170 | return &{ $self->{fastpath}->{ "${eval}." . $self->{TMPVAL} } }( $self->{TMPVAL} ); | |||||||||||||
| 229 | # return $eval->column( $self->{TMPVAL} ); | ||||||||||||||
| 230 | } | ||||||||||||||
| 231 | else | ||||||||||||||
| 232 | { | ||||||||||||||
| 233 | 0 | croak( "Unsupported table storage: '" . ref($eval) . "'" ); | |||||||||||||
| 234 | } | ||||||||||||||
| 235 | } | ||||||||||||||
| 236 | |||||||||||||||
| 237 | =head1 AUTHOR AND COPYRIGHT | ||||||||||||||
| 238 | |||||||||||||||
| 239 | Copyright (c) 2009-2020 by Jens Rehsack: rehsackATcpan.org | ||||||||||||||
| 240 | |||||||||||||||
| 241 | All rights reserved. | ||||||||||||||
| 242 | |||||||||||||||
| 243 | You may distribute this module under the terms of either the GNU | ||||||||||||||
| 244 | General Public License or the Artistic License, as specified in | ||||||||||||||
| 245 | the Perl README file. | ||||||||||||||
| 246 | |||||||||||||||
| 247 | =cut | ||||||||||||||
| 248 | |||||||||||||||
| 249 | 16 | 1; | |||||||||||||