line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Builtin::Hash; |
2
|
4
|
|
|
4
|
|
130
|
use 5.008001; |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
206
|
|
3
|
4
|
|
|
4
|
|
29
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
195
|
|
4
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
801
|
|
5
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.3 $ =~ /(\d+)/g; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
27
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
673
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use overload ( |
10
|
4
|
|
|
|
|
54
|
'""' => \&Class::Builtin::Hash::dump, |
11
|
4
|
|
|
4
|
|
31
|
); |
|
4
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new{ |
14
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
15
|
1
|
|
|
|
|
3
|
my $href = shift; |
16
|
1
|
|
|
|
|
2
|
my %self; |
17
|
1
|
|
|
|
|
9
|
while(my ($k, $v) = each %$href){ |
18
|
1
|
|
|
|
|
7
|
$self{$k} = Class::Builtin->new($v); |
19
|
|
|
|
|
|
|
} |
20
|
1
|
|
|
|
|
7
|
bless \%self, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub clone{ |
24
|
0
|
|
|
0
|
0
|
0
|
__PACKAGE__->new({ %{$_[0]} }); |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
0
|
0
|
sub get { $_[0]->{ $_[1] } } |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
0
|
0
|
sub set { $_[0]->{ $_[1] } = Class::Builtin->new( $_[2] ) } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub unbless { |
32
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
33
|
0
|
|
|
|
|
0
|
my %hash; |
34
|
0
|
|
|
|
|
0
|
while(my ($k, $v) = each %$self){ |
35
|
0
|
0
|
|
|
|
0
|
$hash{$k} = eval { $v->can('unbless') } ? $v->unbless: $v; |
|
0
|
|
|
|
|
0
|
|
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
0
|
\%hash; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub dump { |
41
|
0
|
|
|
0
|
0
|
0
|
local ($Data::Dumper::Terse) = 1; |
42
|
0
|
|
|
|
|
0
|
local ($Data::Dumper::Indent) = 0; |
43
|
0
|
|
|
|
|
0
|
local ($Data::Dumper::Useqq) = 1; |
44
|
0
|
|
|
|
|
0
|
sprintf 'OO(%s)', Data::Dumper::Dumper($_[0]->unbless); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub delete { |
48
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
49
|
0
|
|
|
|
|
0
|
my @deleted = CORE::delete @{$self}{@_}; |
|
0
|
|
|
|
|
0
|
|
50
|
0
|
|
|
|
|
0
|
Class::Builtin::Array->new([@deleted]); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub exists { |
54
|
1
|
|
|
1
|
0
|
464
|
my $self = shift; |
55
|
1
|
|
|
|
|
3
|
my $key = shift; |
56
|
1
|
|
|
|
|
8
|
CORE::exists $self->{$key} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
for my $meth (qw/keys values/){ |
60
|
1
|
|
|
1
|
0
|
3
|
eval qq{ |
|
1
|
|
|
1
|
0
|
13
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
61
|
|
|
|
|
|
|
sub Class::Builtin::Hash::$meth |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
Class::Builtin::Array->new([CORE::$meth \%{\$_[0]}]) |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
croak $@ if $@; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub length{ |
70
|
1
|
|
|
1
|
0
|
2
|
CORE::length keys %{$_[0]}; |
|
1
|
|
|
|
|
7
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub each { |
74
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
75
|
1
|
|
33
|
|
|
5
|
my $block = shift || croak; |
76
|
1
|
|
|
|
|
7
|
while (my ($k, $v) = each %$self){ |
77
|
1
|
|
|
|
|
3
|
$block->($k, $v); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub print { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
0
|
0
|
|
|
|
|
@_ ? CORE::print {$_[0]} %$self : CORE::print %$self; |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub say { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
local $\ = "\n"; |
89
|
0
|
|
|
|
|
|
local $, = ","; |
90
|
0
|
0
|
|
|
|
|
@_ ? CORE::print {$_[0]} %$self : CORE::print %$self; |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub methods { |
96
|
0
|
|
|
|
|
|
Class::Builtin::Array->new( |
97
|
0
|
|
|
0
|
1
|
|
[ sort grep { defined &{$_} } keys %Class::Builtin::Hash:: ] ); |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Scalar::Util related |
101
|
|
|
|
|
|
|
for my $meth (qw/blessed isweak refaddr reftype weaken/){ |
102
|
0
|
|
|
0
|
0
|
|
eval qq{ |
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub Class::Builtin::Hash::$meth |
104
|
|
|
|
|
|
|
{ |
105
|
|
|
|
|
|
|
my \$self = CORE::shift; |
106
|
|
|
|
|
|
|
my \$ret = Scalar::Util::$meth(\$self); |
107
|
|
|
|
|
|
|
__PACKAGE__->new(\$ret); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
croak $@ if $@; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; # End of Class::Builtin::Hash |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Class::Builtin::Hash - Hash as an object |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 VERSION |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$Id: Hash.pm,v 0.3 2009/06/22 15:52:18 dankogai Exp $ |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SYNOPSIS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
use Class::Builtin::Hash; # use Class::Builtin; |
126
|
|
|
|
|
|
|
my $oo = Class::Builtin::Hash->new({key => 'value'}); # OO({key =>'value'}); |
127
|
|
|
|
|
|
|
print $oo->keys->[0]; # 'key' |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 EXPORT |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
None. But see L |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This section is under construction. For the time being, try |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
print Class::Builtin::Hash->new({})->methods->join("\n") |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 TODO |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This section itself is to do :) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 2 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * more methods |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SEE ALSO |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L, L, L L |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 AUTHOR |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Dan Kogai, C<< >> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L, L, L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright 2009 Dan Kogai, all rights reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
166
|
|
|
|
|
|
|
under the same terms as Perl itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |