line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zonemaster::Engine::NSArray; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
157
|
use version; our $VERSION = version->declare("v1.0.3"); |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
171
|
|
4
|
|
|
|
|
|
|
|
5
|
26
|
|
|
26
|
|
2458
|
use 5.014002; |
|
26
|
|
|
|
|
90
|
|
6
|
26
|
|
|
26
|
|
122
|
use warnings; |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
659
|
|
7
|
|
|
|
|
|
|
|
8
|
26
|
|
|
26
|
|
118
|
use Carp; |
|
26
|
|
|
|
|
48
|
|
|
26
|
|
|
|
|
1259
|
|
9
|
26
|
|
|
26
|
|
141
|
use Zonemaster::Engine::Recursor; |
|
26
|
|
|
|
|
62
|
|
|
26
|
|
|
|
|
536
|
|
10
|
26
|
|
|
26
|
|
125
|
use Zonemaster::Engine::Nameserver; |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
495
|
|
11
|
|
|
|
|
|
|
|
12
|
26
|
|
|
26
|
|
114
|
use Moose; |
|
26
|
|
|
|
|
52
|
|
|
26
|
|
|
|
|
165
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'names' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); |
15
|
|
|
|
|
|
|
has 'ary' => ( is => 'ro', isa => 'ArrayRef', default => sub { [] } ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub TIEARRAY { |
18
|
762
|
|
|
762
|
|
3004
|
my ( $class, @names ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
762
|
|
|
|
|
4770
|
return $class->new( { names => [ sort { $a cmp $b } @names ] } ); |
|
4635
|
|
|
|
|
10680
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub STORE { |
24
|
0
|
|
|
0
|
|
0
|
my ( $self, $index, $value ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
croak "STORE forbidden for this type of array."; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub STORESIZE { |
30
|
0
|
|
|
0
|
|
0
|
my ( $self, $index, $value ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
croak "STORESIZE forbidden for this type of array."; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub FETCH { |
36
|
3317
|
|
|
3317
|
|
7766
|
my ( $self, $index ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
3317
|
100
|
|
|
|
80420
|
if ( exists $self->ary->[$index] ) { |
|
|
100
|
|
|
|
|
|
39
|
2628
|
|
|
|
|
61865
|
return $self->ary->[$index]; |
40
|
|
|
|
|
|
|
} |
41
|
689
|
|
|
|
|
17948
|
elsif ( scalar( @{ $self->names } ) == 0 ) { |
42
|
14
|
|
|
|
|
81
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
675
|
|
|
|
|
1401
|
$self->_load_name( shift @{ $self->names } ); |
|
675
|
|
|
|
|
17893
|
|
46
|
675
|
|
|
|
|
3788
|
return $self->FETCH( $index ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub FETCHSIZE { |
51
|
572
|
|
|
572
|
|
7815
|
my ( $self ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
572
|
|
|
|
|
1257
|
while ( my $name = shift @{ $self->names } ) { |
|
909
|
|
|
|
|
23975
|
|
54
|
337
|
|
|
|
|
1274
|
$self->_load_name( $name ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
572
|
|
|
|
|
1064
|
return scalar( @{ $self->ary } ); |
|
572
|
|
|
|
|
13922
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub EXISTS { |
61
|
0
|
|
|
0
|
|
0
|
my ( $self, $index ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
if ( $self->FETCH( $index ) ) { |
64
|
0
|
|
|
|
|
0
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
0
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub DELETE { |
72
|
0
|
|
|
0
|
|
0
|
my ( $self, $index ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
croak "DELETE forbidden for this type of array."; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub CLEAR { |
78
|
0
|
|
|
0
|
|
0
|
my ( $self ) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
croak "CLEAR forbidden for this type of array."; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub PUSH { |
84
|
0
|
|
|
0
|
|
0
|
my ( $self, @values ) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
croak "PUSH forbidden for this type of array."; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub UNSHIFT { |
90
|
0
|
|
|
0
|
|
0
|
my ( $self, @values ) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
croak "UNSHIFT forbidden for this type of array."; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub POP { |
96
|
0
|
|
|
0
|
|
0
|
my ( $self ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
croak "POP forbidden for this type of array."; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub SHIFT { |
102
|
0
|
|
|
0
|
|
0
|
my ( $self ) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
croak "SHIFT forbidden for this type of array."; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub SPLICE { |
108
|
0
|
|
|
0
|
|
0
|
my ( $self, $offset, $length, @values ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
croak "SPLICE forbidden for this type of array."; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub UNTIE { |
114
|
0
|
|
|
0
|
|
0
|
my ( $self ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
return; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _load_name { |
120
|
1012
|
|
|
1012
|
|
2867
|
my ( $self, $name ) = @_; |
121
|
1012
|
|
|
|
|
6267
|
my @addrs = Zonemaster::Engine::Recursor->get_addresses_for( $name ); |
122
|
1012
|
|
|
|
|
5380
|
foreach my $addr ( sort { $a->ip cmp $b->ip } @addrs ) { |
|
631
|
|
|
|
|
2675
|
|
123
|
1638
|
|
|
|
|
14871
|
my $ns = Zonemaster::Engine::Nameserver->new( { name => $name, address => $addr } ); |
124
|
1638
|
100
|
|
|
|
5395
|
if ( not grep { "$ns" eq "$_" } @{ $self->ary } ) { |
|
2698
|
|
|
|
|
105515
|
|
|
1638
|
|
|
|
|
44184
|
|
125
|
1631
|
|
|
|
|
46172
|
push @{ $self->ary }, $ns; |
|
1631
|
|
|
|
|
41294
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1012
|
|
|
|
|
8166
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
26
|
|
|
26
|
|
166449
|
no Moose; |
|
26
|
|
|
|
|
65
|
|
|
26
|
|
|
|
|
127
|
|
133
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Zonemaster::Engine::NSArray - Class implementing arrays that lazily looks up name server addresses from their names |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SYNOPSIS |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
tie @ary, 'Zonemaster::Engine::NSArray', @ns_names |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This class is used for the C<glue> and C<ns> attributes of the |
148
|
|
|
|
|
|
|
L<Zonemaster::Engine::Zone> class. It is initially seeded with a list of |
149
|
|
|
|
|
|
|
names, which will be expanded into proper L<Zonemaster::Engine::Nameserver> |
150
|
|
|
|
|
|
|
objects on demand. Be careful with using Perl functions that act on |
151
|
|
|
|
|
|
|
whole arrays (particularly C<foreach>), since they will usually force |
152
|
|
|
|
|
|
|
the entire array to expand, negating the use of the lazy-loading. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 METHODS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
These are all methods implementing the Perl tie interface. They have no independent use. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item TIEARRAY |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item STORE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item STORESIZE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item FETCH |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item FETCHSIZE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item EXISTS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item DELETE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item CLEAR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item PUSH |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item UNSHIFT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item POP |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item SHIFT |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item SPLICE |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item UNTIE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=back |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Calle Dybedahl, C<< <calle at init.se> >> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |