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