line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Capture; |
2
|
|
|
|
|
|
|
our $VERSION = '0.27'; |
3
|
1
|
|
|
1
|
|
2482
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
54
|
|
5
|
1
|
|
|
1
|
|
86
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
6
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw( refaddr blessed ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
702
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
1010
|
my ( $class, @params ) = @_; |
10
|
1
|
50
|
|
|
|
11
|
if ( @params == 1 ) { |
11
|
1
|
|
|
|
|
146
|
return bless $params[0], $class; |
12
|
|
|
|
|
|
|
} else { |
13
|
0
|
|
|
|
|
0
|
return bless { @params }, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
0
|
0
|
sub data { $_[0] } |
18
|
0
|
|
|
0
|
0
|
0
|
sub scalar { $_[0]{invocant} } # so $$c gets invocant |
19
|
0
|
|
|
0
|
0
|
0
|
sub array { $_[0]{positional} } |
20
|
0
|
|
|
0
|
0
|
0
|
sub hash { $_[0]{named} } |
21
|
1
|
|
|
1
|
0
|
26
|
sub invocant { $_[0]{invocant} } |
22
|
2
|
|
|
2
|
0
|
1158
|
sub positional { $_[0]{positional} } |
23
|
2
|
|
|
2
|
0
|
18
|
sub named { $_[0]{named} } |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
0
|
|
sub keys { CORE::keys %{$_[0]->named} } |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
|
sub values { CORE::values %{$_[0]->named} } |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
0
|
|
sub kv { %{$_[0]->named} } |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
|
sub elems { scalar $_[0]->keys } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub perl { |
33
|
0
|
|
|
0
|
0
|
|
require Data::Dumper; |
34
|
0
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
35
|
0
|
|
|
|
|
|
local $Data::Dumper::Sortkeys = 1; |
36
|
0
|
|
|
|
|
|
local $Data::Dumper::Pad = ' '; |
37
|
0
|
|
|
|
|
|
return __PACKAGE__ . "->new( " . Dumper( $_[0]->data ) . ")\n"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub yaml { |
41
|
0
|
|
|
0
|
0
|
|
require YAML::Syck; |
42
|
|
|
|
|
|
|
# interoperability with other YAML/Syck bindings: |
43
|
0
|
|
|
|
|
|
$YAML::Syck::ImplicitTyping = 1; |
44
|
0
|
|
|
|
|
|
YAML::Syck::Dump( $_[0]->data ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package Data::Capture::Overload; |
48
|
1
|
|
|
1
|
|
6
|
use base qw(Data::Capture); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
108
|
|
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw(blessed refaddr); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
269
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use overload ( |
53
|
1
|
|
|
|
|
13
|
'@{}' => \&array, |
54
|
|
|
|
|
|
|
'%{}' => \&hash, |
55
|
|
|
|
|
|
|
'${}' => \&scalar, |
56
|
|
|
|
|
|
|
fallback => 1, |
57
|
1
|
|
|
1
|
|
6
|
); |
|
1
|
|
|
|
|
2
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my %captures; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new { |
62
|
0
|
|
|
0
|
|
|
my ( $class, @args ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
my $capture = blessed($args[0]) ? $args[0] : Data::Capture->new(@args); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $self = bless \$capture; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$captures{refaddr $self} = $capture; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
|
|
sub DESTROY { delete $captures{refaddr $_[0]} } |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
|
|
sub data { $captures{refaddr $_[0]} } |
76
|
0
|
|
|
0
|
|
|
sub scalar { $captures{refaddr $_[0]}->invocant } |
77
|
0
|
|
|
0
|
|
|
sub array { $captures{refaddr $_[0]}->positional } |
78
|
0
|
|
|
0
|
|
|
sub hash { $captures{refaddr $_[0]}->named } |
79
|
0
|
|
|
0
|
|
|
sub invocant { $captures{refaddr $_[0]}->invocant } |
80
|
0
|
|
|
0
|
|
|
sub positional { $captures{refaddr $_[0]}->positional } |
81
|
0
|
|
|
0
|
|
|
sub named { $captures{refaddr $_[0]}->named } |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
|
|
sub keys { CORE::keys %{$captures{refaddr $_[0]}->named} } |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
|
|
sub values { CORE::values %{$captures{refaddr $_[0]}->named} } |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
|
|
sub kv { map { ( $_, $_[0]->{$_} ) } $_[0]->keys } |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Data::Capture - Perl6 Capture objects |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SEE ALSO |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
L<Data::Bind> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHORS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The Pugs Team E<lt>perl6-compiler@perl.orgE<gt>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright 2006 by Chia-liang Kao and others. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
113
|
|
|
|
|
|
|
under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
See L<http://www.perl.com/perl/misc/Artistic.html> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|