line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Metadata::DB; |
2
|
6
|
|
|
6
|
|
126507
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
203
|
|
3
|
6
|
|
|
6
|
|
5431
|
use LEOCHARRE::DEBUG; |
|
6
|
|
|
|
|
13245
|
|
|
6
|
|
|
|
|
39
|
|
4
|
6
|
|
|
6
|
|
6440
|
use LEOCHARRE::Class2; |
|
6
|
|
|
|
|
28294
|
|
|
6
|
|
|
|
|
747
|
|
5
|
6
|
|
|
6
|
|
50
|
use base 'Metadata::Base'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
11237
|
|
6
|
6
|
|
|
6
|
|
27557
|
use base 'Metadata::DB::Base'; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
3474
|
|
7
|
|
|
|
|
|
|
use Carp; |
8
|
|
|
|
|
|
|
use vars qw($VERSION); |
9
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)/g; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->make_constructor(); |
12
|
|
|
|
|
|
|
__PACKAGE__->make_accessor_setget({ |
13
|
|
|
|
|
|
|
loaded => undef, |
14
|
|
|
|
|
|
|
id => undef, |
15
|
|
|
|
|
|
|
}); |
16
|
|
|
|
|
|
|
no warnings 'redefine'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# overriding Metadata::Base::Write |
19
|
|
|
|
|
|
|
*write = \&save; |
20
|
|
|
|
|
|
|
sub save { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
#my $id = $self->id or confess('no id is set'); |
23
|
|
|
|
|
|
|
my $id; |
24
|
|
|
|
|
|
|
unless( $id = $self->id ){ |
25
|
|
|
|
|
|
|
# gen new |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$id = $self->table_metadata_last_record_id + 1; #thus would set to 1 in none yet |
28
|
|
|
|
|
|
|
$self->id($id); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->_record_entries_delete( $id ); |
33
|
|
|
|
|
|
|
$self->_table_metadata_insert_multiple( $id, $self->get_all ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return $id; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#does obj id exist in db |
40
|
|
|
|
|
|
|
# if id_exists just returns entries_count, might as well be an alias |
41
|
|
|
|
|
|
|
#sub id_exists { $_[0]->entries_count } |
42
|
|
|
|
|
|
|
*id_exists = \&entries_count; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub entries_count { |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
my $id = $self->id or warn("no id is set"); |
47
|
|
|
|
|
|
|
return $self->_record_entries_count($id); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
*elements_count = \&Metadata::Base::size; |
52
|
|
|
|
|
|
|
#sub elements_count { |
53
|
|
|
|
|
|
|
# my $self = shift; |
54
|
|
|
|
|
|
|
# my @e = $self->elements; |
55
|
|
|
|
|
|
|
# my $c = scalar @e; |
56
|
|
|
|
|
|
|
# debug("$c\n"); |
57
|
|
|
|
|
|
|
# return $c; |
58
|
|
|
|
|
|
|
#} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# take object and return meta hash ref of what it holds |
62
|
|
|
|
|
|
|
sub _get_meta_from_object { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $meta = {}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my @elements = $self->elements or return {}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $c = $self->elements_count; |
71
|
|
|
|
|
|
|
debug("[count was $c], have: [@elements]\n"); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
for my $key (@elements){ |
74
|
|
|
|
|
|
|
my @values = $self->get($key); |
75
|
|
|
|
|
|
|
$meta->{$key} = \@values; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
return $meta; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
*get_all = \&_get_meta_from_object; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# overriding Metadata::Base::Read |
83
|
|
|
|
|
|
|
*read = \&load; |
84
|
|
|
|
|
|
|
sub load { |
85
|
|
|
|
|
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $id = $self->id or confess('cannot load, no id is set, no id was passed as arg'); |
88
|
|
|
|
|
|
|
#debug('calling clear..'); |
89
|
|
|
|
|
|
|
#$self->clear; |
90
|
|
|
|
|
|
|
$self->loaded(1); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if ( my $meta= $self->_record_entries_hashref($id) ){ |
93
|
|
|
|
|
|
|
debug("found meta for: $id"); |
94
|
|
|
|
|
|
|
$self->add(%$meta); # what happens if we load twice??? |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
return 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub add { |
101
|
|
|
|
|
|
|
my $self = shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
while( scalar @_){ |
104
|
|
|
|
|
|
|
my($key,$val) = (shift,shift); |
105
|
|
|
|
|
|
|
defined $key and defined $val or confess('undefined values'); |
106
|
|
|
|
|
|
|
#debug("adding $key:$val\n"); |
107
|
|
|
|
|
|
|
# TODO , what if $val is an array ref?? then... is set just recording ONE ???? |
108
|
|
|
|
|
|
|
# Metadata::Base says if the value is array ref, then all vals are recorded |
109
|
|
|
|
|
|
|
$self->set($key, $val); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# lookup |
117
|
|
|
|
|
|
|
sub lookup { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# are there any atts set?? |
121
|
|
|
|
|
|
|
$self->elements or $self->errstr("No elements present, no atts.") and return; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $metaref = $self->get_all; |
124
|
|
|
|
|
|
|
my $found_id = $self->_find_record_id_via_record_entries_hashref($metaref) or return; |
125
|
|
|
|
|
|
|
# load it? i guess yes |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$self->id($found_id); |
128
|
|
|
|
|
|
|
$self->load; |
129
|
|
|
|
|
|
|
$found_id; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
__END__ |