| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package VarGuard; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
66785
|
use 5.006; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
40
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
60
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
VarGuard - safe clean blocks for variables |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.03 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use VarGuard; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
{ |
|
24
|
|
|
|
|
|
|
var_guard { print "$_[0]\n" } my $scalar; |
|
25
|
|
|
|
|
|
|
$scalar = 'abc'; |
|
26
|
|
|
|
|
|
|
} # print "abc\n"; when scalar is destroyed |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
{ |
|
29
|
|
|
|
|
|
|
var_guard { print "@_\n" } my @array; |
|
30
|
|
|
|
|
|
|
... |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
|
34
|
|
|
|
|
|
|
var_guard { print "@_\n" } my %hash; |
|
35
|
|
|
|
|
|
|
... |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
{ |
|
39
|
|
|
|
|
|
|
var_guard { $_[0]() } my $code; |
|
40
|
|
|
|
|
|
|
$code = sub { ... }; |
|
41
|
|
|
|
|
|
|
... |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module is similar to L, except that this module is guard on a variable. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 CAVEAT |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This module will tie something on the variable. So don't use it on a tied variable, |
|
51
|
|
|
|
|
|
|
or tie the guarded variable. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 EXPORT |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
var_guard |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SUBROUTINES |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 var_guard { ...code block... } VAR(could be $, @, %, or any reference) |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
5
|
use base qw(Exporter); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
135
|
|
|
64
|
|
|
|
|
|
|
our @EXPORT = qw(var_guard); |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
|
552
|
use VarGuard::Scalar; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
67
|
1
|
|
|
1
|
|
694
|
use VarGuard::Array; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
40
|
|
|
68
|
1
|
|
|
1
|
|
659
|
use VarGuard::Hash; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
158
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub var_guard(&\[$@%*]) { |
|
71
|
0
|
|
|
0
|
1
|
|
my($cb, $var) = @_; |
|
72
|
0
|
|
|
|
|
|
my $ref_type = ref $var; |
|
73
|
0
|
0
|
0
|
|
|
|
if( $ref_type eq 'SCALAR' or $ref_type eq 'CODE' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
tie $$var, 'VarGuard::Scalar', $cb; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
elsif( $ref_type eq 'ARRAY' ) { |
|
77
|
0
|
|
|
|
|
|
tie @$var, 'VarGuard::Array', $cb; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif( $ref_type eq 'HASH' ) { |
|
80
|
0
|
|
|
|
|
|
tie %$var, 'VarGuard::Hash', $cb; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
else { |
|
83
|
0
|
|
|
|
|
|
die "type: $ref_type is not supported."; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Cindy Wang (CindyLinz) |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
95
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
96
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright 2011 Cindy Wang (CindyLinz). |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
103
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
104
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; # End of VarGuard |