line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NoSQL::PL2SQL; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3710
|
use 5.008009; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use Scalar::Util ; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
91
|
|
8
|
2
|
|
|
2
|
|
13
|
use Carp ; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
165
|
|
9
|
2
|
|
|
2
|
|
30
|
use NoSQL::PL2SQL::Node ; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
10
|
2
|
|
|
2
|
|
10
|
use NoSQL::PL2SQL::Object ; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
11
|
2
|
|
|
2
|
|
16
|
use NoSQL::PL2SQL::Perldata ; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
3328
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
18
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
19
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# This allows declaration use NoSQL::PL2SQL ':all'; |
22
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
23
|
|
|
|
|
|
|
# will save memory. |
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ) ; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ) ; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw() ; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
require XSLoader; |
33
|
|
|
|
|
|
|
XSLoader::load('NoSQL::PL2SQL', $VERSION); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Preloaded methods go here. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our @members = qw( perldata sqltable globals ) ; |
38
|
|
|
|
|
|
|
my @errors = qw( |
39
|
|
|
|
|
|
|
BlessedCaller InvalidDataSource |
40
|
|
|
|
|
|
|
InvalidObjectID UnconnectedDataSource |
41
|
|
|
|
|
|
|
DuplicateObject ObjectNotFound CorruptData |
42
|
|
|
|
|
|
|
TableLockFailure |
43
|
|
|
|
|
|
|
) ; |
44
|
|
|
|
|
|
|
my %errors = () ; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub SQLError { |
47
|
0
|
|
|
0
|
0
|
|
return sqlerror( @_ ) ; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub sqlerror { |
51
|
0
|
|
|
0
|
0
|
|
my $package = shift ; |
52
|
0
|
|
|
|
|
|
my @nvp = () ; |
53
|
0
|
|
|
|
|
|
push @nvp, [ splice @_, 0, 2 ] while @_ ; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
foreach my $a ( @nvp ) { |
56
|
0
|
|
|
|
|
|
my $k = join '::', $package, $a->[0] ; |
57
|
0
|
|
|
|
|
|
$errors{ $k } = $a->[1] ; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
return @errors if wantarray ; |
61
|
0
|
|
|
|
|
|
return [ keys %errors ] ; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub SQLCarp { |
65
|
0
|
|
|
0
|
0
|
|
return sqlcarp( @_ ) ; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub sqlcarp { |
69
|
0
|
|
|
0
|
0
|
|
my $package = shift ; |
70
|
0
|
|
|
|
|
|
my $key = shift ; |
71
|
0
|
|
|
|
|
|
my $error = shift ; |
72
|
0
|
|
|
|
|
|
$error->{Error} = $key ; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $k = join '::', $package, $key ; |
75
|
0
|
0
|
0
|
|
|
|
return &{ $errors{$k} }( $package, $error, @_ ) |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if exists $errors{$k} && ref $errors{$k} eq 'CODE' ; |
77
|
0
|
|
|
|
|
|
carp( $_[-1] ) ; |
78
|
0
|
|
|
|
|
|
return undef ; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub SQLObjectID { |
82
|
0
|
|
|
0
|
0
|
|
return sqlobjectid( @_ ) ; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub sqlobjectid { |
86
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
87
|
0
|
|
|
|
|
|
my $tied = NoSQL::PL2SQL::Object::item( $self )->[1] ; |
88
|
0
|
0
|
|
|
|
|
return $tied unless defined $tied ; |
89
|
0
|
|
|
|
|
|
return $tied->record->{objectid} ; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub SQLObject { |
93
|
0
|
|
|
0
|
0
|
|
return sqlobject( @_ ) ; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub sqlobject { |
97
|
0
|
|
|
0
|
0
|
|
my $package = shift ; |
98
|
0
|
|
|
|
|
|
my @args = @_ ; |
99
|
0
|
|
|
|
|
|
my $dsn = shift ; |
100
|
0
|
0
|
0
|
|
|
|
my $objectid = @_ && ! ref $_[0]? shift( @_ ): undef ; |
101
|
0
|
0
|
0
|
|
|
|
my $object = @_ && ref $_[0]? shift( @_ ): undef ; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
return sqlcarp( $package, $errors[0], {}, @args, |
104
|
|
|
|
|
|
|
'SQLObject must be called as a static method.' ) |
105
|
|
|
|
|
|
|
if ref $package ; |
106
|
|
|
|
|
|
|
return sqlcarp( $package, $errors[1], {}, @args, |
107
|
|
|
|
|
|
|
'Missing or invalid data source.' ) |
108
|
0
|
0
|
|
|
|
|
unless eval { $dsn->db } ; |
|
0
|
|
|
|
|
|
|
109
|
0
|
0
|
0
|
|
|
|
return sqlcarp( $package, $errors[2], {}, @args, |
|
|
|
0
|
|
|
|
|
110
|
|
|
|
|
|
|
'Fetch requires an objectid.' ) or return undef |
111
|
|
|
|
|
|
|
unless defined $objectid || defined $object ; |
112
|
0
|
0
|
|
|
|
|
return sqlcarp( $package, $errors[3], {}, @args, |
113
|
|
|
|
|
|
|
'SQLObject requires a connected database.' |
114
|
|
|
|
|
|
|
.'Use NoSQL::PL2SQL::Node::factory for testing.' ) |
115
|
|
|
|
|
|
|
unless $dsn->dbconnected ; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
0
|
|
|
|
if ( defined $objectid && defined $object ) { |
118
|
0
|
|
|
|
|
|
my $perldata = $dsn->fetch( [ objectid => $objectid, 0 ], |
119
|
|
|
|
|
|
|
[ objecttype => $package, 1 ] ) ; |
120
|
0
|
0
|
|
|
|
|
return sqlcarp( $package, $errors[4], |
121
|
|
|
|
|
|
|
{ $errors[4] => $perldata }, |
122
|
|
|
|
|
|
|
@args, "Duplicate object $objectid." ) |
123
|
|
|
|
|
|
|
if scalar values %$perldata ; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
## write to database |
127
|
0
|
0
|
|
|
|
|
$objectid = NoSQL::PL2SQL::Node->factory( $dsn, $objectid, |
128
|
|
|
|
|
|
|
bless( $object, $package ), $package ) |
129
|
|
|
|
|
|
|
if defined $object ; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $self = bless { sqltable => $dsn }, 'NoSQL::PL2SQL::Clone' ; |
132
|
0
|
|
|
|
|
|
$self->{perldata} = $dsn->fetch( [ objectid => $objectid ], |
133
|
|
|
|
|
|
|
[ objecttype => $package, 1 ] ) ; |
134
|
0
|
|
|
|
|
|
return sqlcarp( $package, $errors[5], {}, @args, |
135
|
|
|
|
|
|
|
"Object not found for object $objectid." ) |
136
|
0
|
0
|
|
|
|
|
unless scalar values %{ $self->{perldata} } ; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
0
|
|
|
|
my $perlnode = $self->record( $objectid ) || { id => 0 } ; |
139
|
0
|
|
|
|
|
|
( $perlnode ) = grep $_->{reftype} eq 'perldata', |
140
|
0
|
0
|
0
|
|
|
|
values %{ $self->{perldata} } |
141
|
|
|
|
|
|
|
unless exists $self->{perldata}->{$objectid} |
142
|
|
|
|
|
|
|
&& $self->{perldata}->{$objectid}->{reftype} |
143
|
|
|
|
|
|
|
eq 'perldata' ; |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
return sqlcarp( $package, $errors[6], { $errors[6] => $self }, @args, |
146
|
|
|
|
|
|
|
'Missing perldata node- possible data corruption.' ) |
147
|
|
|
|
|
|
|
unless $perlnode->{id} ; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$self->{top} = $self->record( $perlnode->{id} )->{refto} ; |
150
|
0
|
|
|
|
|
|
$self->{package} = $package ; |
151
|
0
|
|
|
|
|
|
$self->{reftype} = $self->record->{reftype} ; |
152
|
0
|
|
|
|
|
|
$self->{globals} = { memory => {}, |
153
|
|
|
|
|
|
|
scalarrefs => {}, |
154
|
|
|
|
|
|
|
top => $self->{top}, |
155
|
|
|
|
|
|
|
header => $perlnode, |
156
|
|
|
|
|
|
|
} ; |
157
|
0
|
|
|
|
|
|
$self->{globals}->{clone} = $self ; |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
if ( $self->{reftype} eq 'hashref' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
tie my( %out ), $self ; |
161
|
0
|
|
|
|
|
|
return $self->memorymap( $self->mybless( \%out ) ) ; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
elsif ( $self->{reftype} eq 'arrayref' ) { |
164
|
0
|
|
|
|
|
|
tie my( @out ), $self ; |
165
|
0
|
|
|
|
|
|
return $self->memorymap( $self->mybless( \@out ) ) ; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif ( $self->{reftype} eq 'scalarref' ) { |
168
|
0
|
|
|
|
|
|
$self->loadscalarref( $self->{top} ) ; |
169
|
0
|
|
|
|
|
|
tie my( $out ), $self ; |
170
|
0
|
|
|
|
|
|
return $self->memorymap( $self->mybless( \$out ) ) ; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
else { |
173
|
0
|
|
|
|
|
|
return $self->sqlclone ; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub SQLClone { |
178
|
0
|
|
|
0
|
0
|
|
return sqlclone( @_ ) ; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub sqlclone { |
182
|
0
|
|
|
0
|
0
|
|
my $tied = shift ; |
183
|
0
|
0
|
|
|
|
|
$tied = $tied->sqlobject( @_ ) if @_ >= 2 ; |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $self = NoSQL::PL2SQL::Object::item( $tied )->[1] ; |
186
|
0
|
0
|
|
|
|
|
return $tied unless defined $self ; |
187
|
0
|
|
|
|
|
|
return $self->sqlclone ; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub SQLRollback { |
191
|
0
|
|
|
0
|
0
|
|
return sqlrollback( @_ ) ; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub sqlrollback { |
195
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
196
|
0
|
|
|
|
|
|
my $tied = NoSQL::PL2SQL::Object::item( $self )->[1] ; |
197
|
0
|
0
|
|
|
|
|
return $tied unless defined $tied ; |
198
|
0
|
|
|
|
|
|
$tied->{globals}->{rollback} = 1 ; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |
202
|
|
|
|
|
|
|
__END__ |