line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: SaveLater.pm,v 0.4 2006/03/23 04:36:36 dankogai Exp dankogai $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Tie::SaveLater; |
5
|
3
|
|
|
3
|
|
29016
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
122
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
241
|
|
7
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.4 $ =~ /(\d+)/g; |
8
|
3
|
|
|
3
|
|
17
|
use Carp; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
1259
|
|
9
|
|
|
|
|
|
|
our $DEBUG = 0; |
10
|
|
|
|
|
|
|
my (%OBJ2FN, %FN2OBJ, %OPTIONS); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub make_subclasses{ |
13
|
3
|
|
|
3
|
1
|
41
|
my $pkg = shift; |
14
|
3
|
|
|
|
|
10
|
for my $type (qw/SCALAR ARRAY HASH/){ |
15
|
9
|
|
|
|
|
14
|
my $class = $pkg; my $Type = ucfirst(lc $type); |
|
9
|
|
|
|
|
22
|
|
16
|
9
|
|
|
|
|
721
|
eval qq{ package $class\:\:$type; |
17
|
|
|
|
|
|
|
require Tie\:\:$Type; |
18
|
|
|
|
|
|
|
push our \@ISA, qw($class Tie\:\:Std$Type); }; |
19
|
9
|
50
|
|
|
|
56
|
$@ and croak $@; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
1
|
0
|
sub load { my $class = shift; croak "$class, please implement load()!" } |
|
0
|
|
|
|
|
0
|
|
24
|
0
|
|
|
0
|
1
|
0
|
sub save { my $class = ref shift; croak "$class, please implement save()!" } |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub options{ |
27
|
6
|
|
|
6
|
0
|
10
|
my $self = shift; |
28
|
6
|
100
|
|
|
|
33
|
@_ and $OPTIONS{0+$self} = [ @_ ]; |
29
|
6
|
50
|
|
|
|
19
|
return $OPTIONS{0+$self} ? @{ $OPTIONS{0+$self} } : (); |
|
6
|
|
|
|
|
29
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub super_super{ |
33
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
34
|
1
|
|
|
|
|
3
|
my $name = shift; |
35
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2121
|
|
36
|
1
|
|
|
|
|
2
|
&{ ${ref($self) . "::ISA"}[1] . "::$name"}($self, @_); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
4
|
|
108
|
sub TIEHASH { return shift->TIE('HASH' => @_) }; |
40
|
4
|
|
|
4
|
|
49
|
sub TIEARRAY { return shift->TIE('ARRAY' => @_) }; |
41
|
10
|
|
|
10
|
|
142
|
sub TIESCALAR{ return shift->TIE('SCALAR' => @_) }; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my %types2check = map { $_ => 1 } qw/HASH ARRAY/; |
44
|
|
|
|
|
|
|
sub TIE{ |
45
|
18
|
|
|
18
|
0
|
124
|
my $class = shift; |
46
|
18
|
|
|
|
|
53
|
my $type = shift; |
47
|
18
|
50
|
|
|
|
51
|
my $filename = shift or croak "filename missing"; |
48
|
18
|
|
|
|
|
20
|
my $self; |
49
|
18
|
100
|
|
|
|
329
|
if (-f $filename){ |
50
|
12
|
50
|
|
|
|
71
|
$self = $class->load($filename) or croak "$filename : $!"; |
51
|
12
|
50
|
66
|
|
|
841
|
croak "existing $filename does not store $type" |
52
|
|
|
|
|
|
|
if $types2check{$type} and !$self->isa($type); |
53
|
|
|
|
|
|
|
}else{ |
54
|
|
|
|
|
|
|
$self = |
55
|
6
|
|
|
|
|
17
|
{ HASH => {}, ARRAY => [], SCALAR => \do{ my $scalar }}->{$type}; |
|
6
|
|
|
|
|
33
|
|
56
|
|
|
|
|
|
|
} |
57
|
18
|
|
|
|
|
68
|
bless $self => $class.'::'.$type; |
58
|
18
|
50
|
|
|
|
49
|
$DEBUG and carp sprintf("tied $filename => 0x%x", 0+$self); |
59
|
18
|
100
|
|
|
|
58
|
@_ and $self->options(@_); |
60
|
18
|
|
|
|
|
80
|
$self->_regobj($filename); |
61
|
18
|
|
|
|
|
70
|
$self; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub UNTIE{ |
65
|
18
|
|
|
18
|
|
29
|
my $self = shift; |
66
|
18
|
|
|
|
|
87
|
$self->save; |
67
|
18
|
50
|
|
|
|
2766
|
$DEBUG and carp "untied ", $self->filename; |
68
|
18
|
|
|
|
|
94
|
$self->_unregobj(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
18
|
|
|
18
|
|
16477
|
sub DESTROY{ shift->UNTIE } |
72
|
|
|
|
|
|
|
|
73
|
17
|
|
|
17
|
0
|
76
|
sub filename{ $OBJ2FN{ 0+shift } } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _regobj{ |
76
|
18
|
|
|
18
|
|
432
|
$OBJ2FN{0+$_[0]} = $_[1]; |
77
|
18
|
|
|
|
|
44
|
$FN2OBJ{$_[1]} = 0+$_[0]; |
78
|
18
|
|
|
|
|
29
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _unregobj{ |
82
|
18
|
|
|
18
|
|
72
|
delete $FN2OBJ{ $OBJ2FN{ 0+$_[0] } }; |
83
|
18
|
|
|
|
|
35
|
delete $OPTIONS{ 0+$_[0] }; |
84
|
18
|
|
|
|
|
42
|
delete $OBJ2FN{ 0+$_[0] }; |
85
|
18
|
|
|
|
|
106
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |