line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::AsObject::Array; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
4
|
|
|
4
|
|
80
|
$Data::AsObject::Array::VERSION = '0.07'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Base class for Data::AsObject arrayrefs |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
113
|
|
9
|
4
|
|
|
4
|
|
33
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
118
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
19
|
use Carp qw(carp croak); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
243
|
|
12
|
4
|
|
|
4
|
|
27
|
use Data::AsObject qw(); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
94
|
|
13
|
4
|
|
|
4
|
|
20
|
use namespace::clean -except => [qw/get/]; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
33
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get { |
17
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
18
|
1
|
|
|
|
|
3
|
my $index = shift; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
5
|
ref($self) =~ /^.*::(\w+)$/; |
21
|
1
|
|
|
|
|
3
|
my $mode = $1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# user wants to fetch a value |
24
|
1
|
50
|
|
|
|
4
|
if (defined $index) { |
25
|
|
|
|
|
|
|
# the value exists |
26
|
1
|
50
|
|
|
|
4
|
if ( exists $self->[$index] ) { |
27
|
1
|
|
|
|
|
2
|
my $data = $self->[$index]; |
28
|
|
|
|
|
|
|
|
29
|
1
|
50
|
|
|
|
4
|
if ( $Data::AsObject::__check_type->($data) eq "ARRAY" ) { |
|
|
50
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
return bless $data, "Data::AsObject::Array::$mode"; |
31
|
|
|
|
|
|
|
} elsif ( $Data::AsObject::__check_type->($data) eq "HASH" ) { |
32
|
0
|
|
|
|
|
0
|
return bless $data, "Data::AsObject::Hash::$mode"; |
33
|
|
|
|
|
|
|
} else { |
34
|
1
|
|
|
|
|
4
|
return $data; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
# the value does not exist |
37
|
|
|
|
|
|
|
} else { |
38
|
0
|
|
|
|
|
0
|
my $msg = "Attempting to access non-existing array index [$index]!"; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
if ($mode eq 'Strict') |
|
|
0
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
|
|
0
|
carp $msg; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($mode eq 'Loose') |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
0
|
croak $msg; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
0
|
carp "Array accessor get requires index argument!" |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub list |
57
|
|
|
|
|
|
|
{ |
58
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
59
|
2
|
50
|
|
|
|
6
|
croak "List does not accept arguments" if @_; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
3
|
my $mode; |
62
|
2
|
50
|
|
|
|
13
|
$mode = 'strict' if $self->isa('Data::AsObject::Array::Strict'); |
63
|
2
|
50
|
|
|
|
27
|
$mode = 'loose' if $self->isa('Data::AsObject::Array::Loose'); |
64
|
2
|
50
|
|
|
|
15
|
$mode = 'silent' if $self->isa('Data::AsObject::Array::Silent'); |
65
|
2
|
50
|
|
|
|
6
|
carp "Unknown class used as Data::AsObject::Array" unless $mode; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
3
|
my @array; |
68
|
2
|
|
|
|
|
5
|
foreach my $value (@$self) |
69
|
|
|
|
|
|
|
{ |
70
|
6
|
100
|
|
|
|
13
|
$Data::AsObject::__check_type->($value) |
71
|
|
|
|
|
|
|
? push @array, Data::AsObject::__bless_dao($value, $mode) |
72
|
|
|
|
|
|
|
: push @array, $value; |
73
|
|
|
|
|
|
|
} |
74
|
2
|
|
|
|
|
15
|
return @array; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
package Data::AsObject::Array::Strict; |
78
|
|
|
|
|
|
|
BEGIN { |
79
|
4
|
|
|
4
|
|
6963
|
$Data::AsObject::Array::Strict::VERSION = '0.07'; |
80
|
|
|
|
|
|
|
} |
81
|
4
|
|
|
4
|
|
26
|
use base 'Data::AsObject::Array'; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
436
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
package Data::AsObject::Array::Loose; |
84
|
|
|
|
|
|
|
BEGIN { |
85
|
4
|
|
|
4
|
|
68
|
$Data::AsObject::Array::Loose::VERSION = '0.07'; |
86
|
|
|
|
|
|
|
} |
87
|
4
|
|
|
4
|
|
20
|
use base 'Data::AsObject::Array'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
328
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
package Data::AsObject::Array::Silent; |
90
|
|
|
|
|
|
|
BEGIN { |
91
|
4
|
|
|
4
|
|
78
|
$Data::AsObject::Array::Silent::VERSION = '0.07'; |
92
|
|
|
|
|
|
|
} |
93
|
4
|
|
|
4
|
|
19
|
use base 'Data::AsObject::Array'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
275
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |