| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Scalar::Footnote - Attach hidden scalars to references |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Data::Dumper; |
|
8
|
|
|
|
|
|
|
use Scalar::Footnote; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $obj = Foo->new; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# attach invisible footnote to $obj: |
|
13
|
|
|
|
|
|
|
$obj->Scalar::Footnote::set( my_key => 'my footnote' ); |
|
14
|
|
|
|
|
|
|
print Dumper( $obj ); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# get it back: |
|
17
|
|
|
|
|
|
|
my $note = $obj->Scalar::Footnote::get( 'my_key' ); |
|
18
|
|
|
|
|
|
|
print "footnote: $note\n"; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# remove it: |
|
21
|
|
|
|
|
|
|
my $note = $obj->Scalar::Footnote::remove( 'my_key' ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package Scalar::Footnote; |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
28399
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
42
|
|
|
28
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
5
|
use Carp qw( carp croak confess ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
94
|
|
|
31
|
1
|
|
|
1
|
|
649
|
use Scalar::Footnote::Functions qw( get_footnote set_footnote remove_footnote ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
781
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '0.99_02'; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
|
36
|
3
|
|
|
3
|
0
|
16
|
my $class = shift; |
|
37
|
3
|
|
|
|
|
7
|
my $self = bless {}, $class; |
|
38
|
3
|
|
|
|
|
10
|
$self->init( @_ ); |
|
39
|
3
|
|
|
|
|
9
|
return $self; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
3
|
|
|
3
|
0
|
6
|
sub init { return $_[0]; } |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub set_value_for { |
|
45
|
4
|
|
|
4
|
1
|
382
|
my $self = shift; |
|
46
|
4
|
|
|
|
|
4
|
my $key = shift; |
|
47
|
4
|
|
|
|
|
11
|
$self->{"$key"} = shift; |
|
48
|
4
|
|
|
|
|
9
|
return $self; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_value_for { |
|
52
|
5
|
|
|
5
|
1
|
868
|
my $self = shift; |
|
53
|
5
|
|
|
|
|
7
|
my $key = shift; |
|
54
|
5
|
|
|
|
|
18
|
$self->{"$key"}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub remove_value_for { |
|
58
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
59
|
2
|
|
|
|
|
3
|
my $key = shift; |
|
60
|
2
|
|
|
|
|
10
|
delete $self->{"$key"}; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub attach_to { |
|
64
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
|
65
|
2
|
|
|
|
|
2
|
my $thing = shift; |
|
66
|
|
|
|
|
|
|
|
|
67
|
2
|
50
|
|
|
|
6
|
croak( "can't set footnote object: '$thing' is not a ref!" ) unless ref( $thing ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
7
|
set_footnote( $thing => $self ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
9
|
return $self; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
75
|
|
|
|
|
|
|
# Class Methods |
|
76
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub attach_new_footnote_object_to { |
|
79
|
2
|
|
|
2
|
1
|
3
|
my $class = shift; |
|
80
|
2
|
|
|
|
|
3
|
my $thing = shift; |
|
81
|
2
|
|
|
|
|
5
|
return Scalar::Footnote->new->attach_to( $thing ); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_footnote_object_for { |
|
85
|
6
|
|
|
6
|
1
|
5
|
my $class = shift; |
|
86
|
6
|
|
|
|
|
7
|
my $thing = shift; |
|
87
|
|
|
|
|
|
|
|
|
88
|
6
|
50
|
|
|
|
13
|
confess( "can't get footnote object: '$thing' is not a ref!" ) unless ref( $thing ); |
|
89
|
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
15
|
my $note = get_footnote( $thing ); |
|
91
|
|
|
|
|
|
|
|
|
92
|
6
|
100
|
|
|
|
40
|
return unless defined( $note ); |
|
93
|
|
|
|
|
|
|
|
|
94
|
4
|
50
|
|
|
|
13
|
croak( "footnote object for '$thing' is not a Scalar::Footnote object (it's '$note')" ) |
|
95
|
|
|
|
|
|
|
unless UNIVERSAL::isa( $note, 'Scalar::Footnote' ); |
|
96
|
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
11
|
return $note; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_or_create_footnote_object_for { |
|
101
|
3
|
|
|
3
|
0
|
3
|
my $class = shift; |
|
102
|
3
|
|
|
|
|
4
|
my $thing = shift; |
|
103
|
3
|
|
66
|
|
|
8
|
return $class->get_footnote_object_for( $thing ) || |
|
104
|
|
|
|
|
|
|
$class->attach_new_footnote_object_to( $thing ); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
108
|
|
|
|
|
|
|
# Pseudo Class Methods |
|
109
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub set { |
|
112
|
3
|
|
|
3
|
1
|
549
|
my $thing = shift; |
|
113
|
3
|
|
|
|
|
4
|
my $key = shift; |
|
114
|
3
|
|
|
|
|
3
|
my $value = shift; |
|
115
|
|
|
|
|
|
|
|
|
116
|
3
|
50
|
|
|
|
9
|
croak( "can't set footnote for '$thing' - it's not a ref!" ) |
|
117
|
|
|
|
|
|
|
unless ref( $thing ); |
|
118
|
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
10
|
my $note = Scalar::Footnote->get_or_create_footnote_object_for( $thing ); |
|
120
|
|
|
|
|
|
|
|
|
121
|
3
|
|
|
|
|
7
|
$note->set_value_for( $key => $value ); |
|
122
|
|
|
|
|
|
|
|
|
123
|
3
|
|
|
|
|
7
|
return $thing; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub get { |
|
127
|
2
|
|
|
2
|
1
|
3
|
my $thing = shift; |
|
128
|
2
|
|
|
|
|
3
|
my $key = shift; |
|
129
|
|
|
|
|
|
|
|
|
130
|
2
|
50
|
|
|
|
530
|
croak( "can't get footnote for '$thing' - it's not a ref!" ) |
|
131
|
|
|
|
|
|
|
unless ref( $thing ); |
|
132
|
|
|
|
|
|
|
|
|
133
|
2
|
|
50
|
|
|
6
|
my $note = Scalar::Footnote->get_footnote_object_for( $thing ) || return; |
|
134
|
|
|
|
|
|
|
|
|
135
|
2
|
|
|
|
|
5
|
return $note->get_value_for( $key ); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub remove { |
|
139
|
1
|
|
|
1
|
1
|
493
|
my $thing = shift; |
|
140
|
1
|
|
|
|
|
2
|
my $key = shift; |
|
141
|
|
|
|
|
|
|
|
|
142
|
1
|
50
|
|
|
|
3
|
croak( "can't remove footnote for '$thing' - it's not a ref!" ) |
|
143
|
|
|
|
|
|
|
unless ref( $thing ); |
|
144
|
|
|
|
|
|
|
|
|
145
|
1
|
|
50
|
|
|
3
|
my $note = Scalar::Footnote->get_footnote_object_for( $thing ) || return; |
|
146
|
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
3
|
return $note->remove_value_for( $key ); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub remove_all { |
|
151
|
1
|
|
|
1
|
1
|
2
|
my $thing = shift; |
|
152
|
|
|
|
|
|
|
|
|
153
|
1
|
50
|
|
|
|
2
|
croak( "can't remove all footnotes for '$thing' - it's not a ref!" ) |
|
154
|
|
|
|
|
|
|
unless ref( $thing ); |
|
155
|
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
3
|
my $note = remove_footnote( $thing ); |
|
157
|
|
|
|
|
|
|
|
|
158
|
1
|
50
|
|
|
|
5
|
return unless defined( $note ); |
|
159
|
|
|
|
|
|
|
|
|
160
|
1
|
50
|
|
|
|
3
|
carp( "footnote for '$thing' is not a Scalar::Footnote object (it's '$note')" ) |
|
161
|
|
|
|
|
|
|
unless UNIVERSAL::isa( $note, 'Scalar::Footnote' ); |
|
162
|
|
|
|
|
|
|
|
|
163
|
1
|
|
|
|
|
3
|
return $note; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__END__ |