| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Clone; |
|
3
|
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
118
|
use strict; |
|
|
8
|
|
|
|
|
107
|
|
|
|
8
|
|
|
|
|
173
|
|
|
5
|
8
|
|
|
8
|
|
119
|
use Carp; |
|
|
8
|
|
|
|
|
73
|
|
|
|
8
|
|
|
|
|
144
|
|
|
6
|
8
|
|
|
8
|
|
135
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); |
|
|
8
|
|
|
|
|
73
|
|
|
|
8
|
|
|
|
|
114
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
|
|
|
|
|
|
require DynaLoader; |
|
10
|
|
|
|
|
|
|
require AutoLoader; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@EXPORT = qw(); |
|
17
|
|
|
|
|
|
|
@EXPORT_OK = qw( clone ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$VERSION = '0.22'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
bootstrap Clone $VERSION; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
|
28
|
|
|
|
|
|
|
__END__ |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Clone - recursively copy Perl datatypes |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use Clone; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
push @Foo::ISA, 'Clone'; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$a = new Foo; |
|
41
|
|
|
|
|
|
|
$b = $a->clone(); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# or |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Clone qw(clone); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$a = { 'foo' => 'bar', 'move' => 'zig' }; |
|
48
|
|
|
|
|
|
|
$b = [ 'alpha', 'beta', 'gamma', 'vlissides' ]; |
|
49
|
|
|
|
|
|
|
$c = new Foo(); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$d = clone($a); |
|
52
|
|
|
|
|
|
|
$e = clone($b); |
|
53
|
|
|
|
|
|
|
$f = clone($c); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module provides a clone() method which makes recursive |
|
58
|
|
|
|
|
|
|
copies of nested hash, array, scalar and reference types, |
|
59
|
|
|
|
|
|
|
including tied variables and objects. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
clone() takes a scalar argument and an optional parameter that |
|
63
|
|
|
|
|
|
|
can be used to limit the depth of the copy. To duplicate lists, |
|
64
|
|
|
|
|
|
|
arrays or hashes, pass them in by reference. e.g. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $copy = clone (\@array); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# or |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my %copy = %{ clone (\%hash) }; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
For a slower, but more flexible solution see Storable's dclone(). |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Ray Finch, rdf@cpan.org |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Copyright 2001 Ray Finch. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
|
82
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Storable(3). |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|