1 |
############################################ |
2 |
# |
3 |
# $Id: Tangram.pm,v 1.6 2003/04/09 07:11:01 joko Exp $ |
4 |
# |
5 |
# $Log: Tangram.pm,v $ |
6 |
# Revision 1.6 2003/04/09 07:11:01 joko |
7 |
# minor fix |
8 |
# |
9 |
# Revision 1.5 2003/04/09 02:09:47 joko |
10 |
# bugfix: check for existance of '->close'-method before calling it on the 'RESULTHANDLE'-instance |
11 |
# |
12 |
# Revision 1.4 2003/03/27 15:31:15 joko |
13 |
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
14 |
# |
15 |
# Revision 1.3 2003/01/31 06:34:49 joko |
16 |
# + fixes to 'getNextEntry' and 'getStatus' |
17 |
# |
18 |
# Revision 1.2 2002/12/05 08:01:26 joko |
19 |
# + sub getStatus utilizing isEmpty to determine if result is set/unset and/or filled/unfilled |
20 |
# |
21 |
# Revision 1.1 2002/11/29 04:55:45 joko |
22 |
# + initial check-in |
23 |
# |
24 |
# |
25 |
############################################ |
26 |
|
27 |
|
28 |
package Data::Storage::Result::Tangram; |
29 |
|
30 |
use strict; |
31 |
use warnings; |
32 |
|
33 |
use base ("Data::Storage::Result::Abstract"); |
34 |
use Data::Dumper; |
35 |
use Data::Mungle::Compare::Struct qw( isEmpty ); |
36 |
|
37 |
sub DESTROY { |
38 |
my $self = shift; |
39 |
|
40 |
my $is_object = 0; |
41 |
|
42 |
#$logger->debug( __PACKAGE__ . "->" . "DESTROY" ); |
43 |
#eval { |
44 |
#print "ref: ", ref($self->{RESULTHANDLE}), "\n"; |
45 |
|
46 |
# object handle destructor |
47 |
if ($self->{resulthandle_type} eq 'Tangram::Cursor') { |
48 |
#$self->{RESULTHANDLE} && ref($self->{RESULTHANDLE}) && |
49 |
#ref($self->{RESULTHANDLE}) && $self->{RESULTHANDLE}->can('close') && $self->{RESULTHANDLE}->close(); |
50 |
$self->{RESULTHANDLE}->close(); |
51 |
} |
52 |
|
53 |
# delete ref? |
54 |
delete $self->{RESULTHANDLE}; |
55 |
} |
56 |
|
57 |
sub getNextEntry { |
58 |
my $self = shift; |
59 |
|
60 |
return if !$self->{RESULTHANDLE}; |
61 |
$self->{resulthandle_type} = ref($self->{RESULTHANDLE}) if !$self->{resulthandle_type}; |
62 |
|
63 |
# is result already opened? |
64 |
if ($self->{open}) { |
65 |
$self->{entry_count}++; |
66 |
|
67 |
# NEW as of 2003-06-24: RESULTHANDLE == ARRAY |
68 |
return $self->{RESULTHANDLE}->[$self->{entry_count}] if (ref($self->{RESULTHANDLE}) eq 'ARRAY'); |
69 |
|
70 |
return $self->{RESULTHANDLE}->next() |
71 |
if $self->{resulthandle_type} eq 'Tangram::Cursor'; |
72 |
return $self->{members}->[$self->{entry_count}] |
73 |
if $self->{resulthandle_type} eq 'Set::Object'; |
74 |
|
75 |
# open result! |
76 |
} else { |
77 |
$self->{entry_count} = 0; |
78 |
$self->{open} = 1; |
79 |
|
80 |
# NEW as of 2003-06-24: RESULTHANDLE == ARRAY |
81 |
return $self->{RESULTHANDLE}->[$self->{entry_count}] if (ref($self->{RESULTHANDLE}) eq 'ARRAY'); |
82 |
|
83 |
return $self->{RESULTHANDLE}->execute() |
84 |
if $self->{resulthandle_type} eq 'Tangram::Cursor'; |
85 |
#print Dumper($self->{RESULTHANDLE}->members()); exit; |
86 |
if ($self->{resulthandle_type} eq 'Set::Object') { |
87 |
my @members = $self->{RESULTHANDLE}->members(); |
88 |
$self->{members} = \@members; |
89 |
return $self->{members}->[$self->{entry_count}]; |
90 |
} |
91 |
} |
92 |
} |
93 |
|
94 |
sub getStatus { |
95 |
my $self = shift; |
96 |
my $status; |
97 |
|
98 |
$self->{resulthandle_type} ||= ''; |
99 |
|
100 |
if ($self->{resulthandle_type} eq 'Tangram::Cursor') { |
101 |
=pod |
102 |
print Dumper($self->{RESULTHANDLE}); |
103 |
$status = { |
104 |
err => $self->{RESULTHANDLE}->err, |
105 |
errstr => $self->{RESULTHANDLE}->errstr, |
106 |
state => $self->{RESULTHANDLE}->state, |
107 |
}; |
108 |
=cut |
109 |
} |
110 |
if ($self->{resulthandle_type} eq 'Set::Object') { |
111 |
#print Dumper($self->{RESULTHANDLE}->members()); |
112 |
$status = { |
113 |
empty => isEmpty($self->{RESULTHANDLE}), |
114 |
}, |
115 |
} |
116 |
return $status; |
117 |
} |
118 |
|
119 |
|
120 |
1; |