line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Curse; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Acme::Curse - Remove the blessing that lay on references |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Acme::Curse qw(curse); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $unblessed_ref = curse($object); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Did you ever want to droo the blessing of an object? Well, now you can: |
16
|
|
|
|
|
|
|
Acme::Curse unblesses reference by returning a shallow, non-blessed copy |
17
|
|
|
|
|
|
|
of the object. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Currently only references to scalar, hashes, arrays and code objects can |
20
|
|
|
|
|
|
|
be unblessed. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Exported subs: |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=over 4 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item curse |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Unblesses a reference to an object. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=back |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 BUGS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
None known, but surely there are many. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 AUTHOR |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Moritz Lenz, L, L |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Copyright (C) 2008 Moritz Lenz |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module is free software; it can be used under the same terms as perl |
45
|
|
|
|
|
|
|
itself. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
45007
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
50
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
51
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
33
|
|
52
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(reftype); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
525
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our @EXPORT_OK = qw(curse); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub curse { |
57
|
4
|
|
|
4
|
1
|
573
|
my ($obj) = @_; |
58
|
4
|
|
|
|
|
13
|
my $type = reftype($obj); |
59
|
4
|
100
|
|
|
|
21
|
if ($type eq 'HASH') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
60
|
1
|
|
|
|
|
13
|
return { %$obj }; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ($type eq 'ARRAY') { |
63
|
1
|
|
|
|
|
6
|
return [ @$obj ]; |
64
|
|
|
|
|
|
|
} elsif ($type eq 'SCALAR'){ |
65
|
1
|
|
|
|
|
2
|
my $copy = $$obj; |
66
|
1
|
|
|
|
|
9
|
return \$copy; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($type eq 'CODE') { |
69
|
1
|
|
|
0
|
|
9
|
return sub { goto &$obj }; |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
|
die "Don't know how to curse ${type}s"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |