blib/lib/FTN/Outbound/BSO.pm

filter: Statementstmt 32.8% 93 / 283 Branchbran 14.6% 31 / 212 Conditioncond 14.0% 19 / 135 MC/DCmcdc 2.8% 2 / 70 Subroutinesub 66.6% 14 / 21 Podpod 100% 6 / 6 totaltotal 22.7% 165 / 727 SCAR 92.9
CC
152
Cov
23%
addr_file_to_change
1482.0
scan
600.0
new
258.1
CRAP 10824.2
↑ Summary
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package FTN::Outbound::BSO;
6 3 $FTN::Outbound::BSO::VERSION = '20160516';
7 # fts-5005.002 BinkleyTerm Style Outbound
8 # except s/Continuous/Crash/g
9  
10 3 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Encode::Locale ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Fcntl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use FTN::Addr ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use FTN::Outbound::Reference_file ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 my %flavour_extension = ( immediate => [ qw/ iut ilo / ], # Xut (netmail) Xlo (reference file) by fts-5005.002
20 # continuous => [ qw/ c c / ], # except this one
21 crash => [ qw/ cut clo / ],
22 direct => [ qw/ dut dlo / ],
23 normal => [ qw/ out flo / ],
24 hold => [ qw/ hut hlo / ],
25 );
26 # Reference files consist of a number of lines (terminated by 0x0a or 0x0d,0x0a) each consisting of the name of the file to transfer to the remote system.
27  
28 # file_type => extension. both keys and values should be unique in their sets
29 # content notes are from fts-5005.002
30 3 my %control_file_extension = ( file_request => 'req', # file requests
31 # The format of request files is documented in FTS-0006.
32 busy => 'bsy', # busy control file.
33 # may contain one line of PID information (less than 70 characters).
34 call => 'csy', # call control file
35 # may contain one line of PID information (less than 70 characters).
36 hold => 'hld', # hold control file
37 # must contain a one line string with the expiration of the hold period expressed in UNIX-time.
38 # the second line of an hld file may contain one line of PID information. (Less than 70 characters)
39 try => 'try', # try control file
40 # A try file must contain one line string with a diagnostic message. It is for information purposes only.
41 # the second line of a try file may contain one line of PID information. ( < 70 characters)
42 );
43  
44 =head1 NAME
45  
46 FTN::Outbound::BSO - Object-oriented module for working with BinkleyTerm Style Outbound.
47  
48 =head1 VERSION
49  
50 version 20160516
51  
52 =head1 SYNOPSIS
53  
54 use Log::Log4perl ();
55 use Encode ();
56 use FTN::Outbound::BSO ();
57  
58 Log::Log4perl -> easy_init( $Log::Log4perl::INFO );
59  
60 my $bso = FTN::Outbound::BSO -> new( outbound_root => '/var/lib/ftn/outbound',
61 domain => 'fidonet',
62 zone => 2,
63 domain_abbrev => { fidonet => '_out',
64 homenet => 'leftnet',
65 },
66 maximum_session_time => 3600, # one hour
67 ) or die 'cannot create bso object';
68  
69 my $addr = FTN::Addr -> new( '2:451/30' );
70  
71 sub poll {
72 my $addr = shift;
73 my $bso = shift;
74  
75 my $flo = $bso -> addr_file_to_change( $addr,
76 'reference_file',
77 'normal'
78 );
79  
80 open my $fh, '>>', $flo
81 or die sprintf 'cannot open %s: %s', $flo, $!;
82  
83 print $fh '';
84  
85 close $fh;
86 }
87  
88 $bso -> busy_protected_sub( $addr,
89 \ &poll,
90 );
91  
92 =head1 DESCRIPTION
93  
94 FTN::Outbound::BSO module is for working with BinkleyTerm Style Outbound in FTN following specifications from fts-5005.002 document. Figuring out correct file to process might be a tricky process: different casing, few our main domains, other differences. This module helps with this task.
95  
96 =head1 OBJECT CREATION
97  
98 =head2 new
99  
100 Expects parameters as hash:
101  
102 outbound_root - directory path as a character string where whole outbound is located. Mandatory parameter. This directory should exist.
103  
104 By standard constructor needs our domain and zone. They can be provided as:
105  
106 our_addr - either FTN::Addr object representing our address or our address as a string which will be passed to FTN::Addr constructor.
107  
108 or as a pair:
109  
110 domain - domain part of our address as described in frl-1028.002.
111 zone - our zone in that domain
112  
113 At least one of the ways should be provided. In case both are our_addr has higher priority.
114  
115 domain_abbrev - hash reference where keys are known domains and values are directory names (without extension) in outbound_root for those domains. Mandatory parameter.
116  
117 reference_file_read_line_transform_sub - reference to a function that receives an octet string and returns a character string. Will be passed to FTN::Outbound::Reference_file constructor. If not provided reference file content won't be processed.
118  
119 maximum_session_time - maximum session time in seconds. If provided, all found busy files older than 2 * value will be removed during outbound scan.
120  
121 Returns newly created object on success.
122  
123 =cut
124  
125 sub new {
126 2 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine new: called CC=33 SCAR=55.5
Pod documented
127  
128 2 ▶ ref( my $class = shift ) and $logger -> logcroak( "I'm only a class method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $class = shift()) and $logger->logcroak("I'm only a class method!") 0 2 2
129  
130 return
131 2 ▶ unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
132  
133 2 ▶ $logger -> logdie( sprintf 'constructor expects even number of arguments, but received %d of them',
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 2 2
134 scalar @_,
135 )
136 if @_ % 2;
137  
138 2 my %option = @_;
139 2 my %self;
140  
141 # validating
142 # mandatory parameters
143 $logger -> logdie( 'mandatory outbound_root is not provided' )
144 2 ▶ unless exists $option{outbound_root};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"outbound_root"} 0 2 2
145  
146 # outbound_root
147 2 my $outbound_root_fs = Encode::encode( locale_fs => $option{outbound_root} );
148  
149 2 ▶ unless ( -e $outbound_root_fs ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $outbound_root_fs) 0 2 2
150 $logger -> warn( sprintf 'outbound_root (%s) directory does not exist',
151 $option{outbound_root},
152 0 );
153  
154 0 return;
155 }
156  
157 2 ▶ unless ( -d _ ) { # if it exists it should be a directory
Branch: 1 branch
BranchTrueFalseTotal
unless (-d _) 0 2 2
158 $logger -> warn( sprintf 'outbound_root (%s) does not point to the directory',
159 $option{outbound_root},
160 0 );
161  
162 0 return;
163 }
164  
165 2 $self{outbound_root} = $option{outbound_root};
166 2 $self{outbound_root_fs} = $outbound_root_fs;
167  
168  
169 # our_addr or ( domain + zone )
170 2 ▶ if ( exists $option{our_addr}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{'our_addr'} and $option{'our_addr'}) { } 0 2 2
Condition33%1/3
exists $option{"our_addr"} and $option{"our_addr"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $option{"our_addr"} and $option{"our_addr"}
exists $option{"our_addr"} $option{"our_addr"}
Truth table33%1/3
A and B
A= exists $option{"our_addr"}B= $option{"our_addr"}
ABresult
0X0
100
111
171 && $option{our_addr}
172 ) {
173 0 ▶ if ( ref $option{our_addr}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $option{'our_addr'} and builtin::blessed($option{'our_addr'}) and $option{'our_addr'}->isa('FTN::Addr')) { } 0 0 0
Condition0%0/6
ref $option{"our_addr"} and builtin::blessed($option{"our_addr"}) and $option{"our_addr"}->isa("FTN::Addr")
!ll&&!rl&&r
000
ref $option{"our_addr"} and builtin::blessed($option{"our_addr"})
!ll&&!rl&&r
000
MC/DC0%0/3
ref $option{"our_addr"} and builtin::blessed($option{"our_addr"}) and $option{"our_addr"}->isa("FTN::Addr")
ref $option{"our_addr"} builtin::blessed($option{"our_addr"}) $option{"our_addr"}->isa("FTN::Addr")
Truth table0%0/4
A and B and C
A= ref $option{"our_addr"}B= builtin::blessed($option{"our_addr"})C= $option{"our_addr"}->isa("FTN::Addr")
ABCresult
0XX0
10X0
1100
1111
174 && Scalar::Util::blessed $option{our_addr}
175 && $option{our_addr} -> isa( 'FTN::Addr' )
176 ) {
177 0 $self{our_addr} = $option{our_addr};
178 } else {
179 $self{our_addr} = FTN::Addr -> new( $option{our_addr} )
180 or $logger -> logdie( sprintf 'incorrect value of our_addr: %s',
181 $option{our_addr},
182 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self{"our_addr"} = "FTN::Addr"->new($option{"our_addr"}) or $logger->logdie(sprintf('incorrect value of our_addr: %s', $option{"our_addr"})) 0 0 0
183 }
184 0 $self{domain} = $self{our_addr} -> domain;
185 0 $self{zone} = $self{our_addr} -> zone;
186 } else {
187 $logger -> logdie( 'domain is not provided' )
188 unless exists $option{domain}
189 2 ▶ && $option{domain};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"domain"} and $option{"domain"} 0 2 2
Condition33%1/3
exists $option{"domain"} and $option{"domain"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $option{"domain"} and $option{"domain"}
exists $option{"domain"} $option{"domain"}
Truth table33%1/3
A and B
A= exists $option{"domain"}B= $option{"domain"}
ABresult
0X0
100
111
190  
191 $logger -> logdie( sprintf 'domain (%s) is not valid',
192 $option{domain},
193 )
194 2 ▶ unless $option{domain} =~ m/^[a-z\d_~-]{1,8}$/; # frl-1028.002
Branch: 1 branch
BranchTrueFalseTotal
unless $option{"domain"} =~ /^[a-z\d_~-]{1,8}$/ 0 2 2
195  
196 $logger -> logdie( 'zone is not provided' )
197 unless exists $option{zone}
198 2 ▶ && $option{zone};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"zone"} and $option{"zone"} 0 2 2
Condition33%1/3
exists $option{"zone"} and $option{"zone"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $option{"zone"} and $option{"zone"}
exists $option{"zone"} $option{"zone"}
Truth table33%1/3
A and B
A= exists $option{"zone"}B= $option{"zone"}
ABresult
0X0
100
111
199  
200 $logger -> logdie( sprintf 'zone (%s) is not valid',
201 $option{zone},
202 )
203 unless $option{zone} =~ m/^\d+$/ # FRL-1002.001, frl-1028.002
204 && 1 <= $option{zone} # FRL-1002.001, frl-1028.002
205 2 ▶ && $option{zone} <= 32767; # FRL-1002.001, frl-1028.002
Branch: 1 branch
BranchTrueFalseTotal
unless $option{"zone"} =~ /^\d+$/ and 1 <= $option{"zone"} and $option{"zone"} <= 32767 0 2 2
Condition33%2/6
$option{"zone"} =~ /^\d+$/ and 1 <= $option{"zone"} and $option{"zone"} <= 32767
!ll&&!rl&&r
002
$option{"zone"} =~ /^\d+$/ and 1 <= $option{"zone"}
!ll&&!rl&&r
002
MC/DC0%0/3
$option{"zone"} =~ /^\d+$/ and 1 <= $option{"zone"} and $option{"zone"} <= 32767
$option{"zone"} =~ /^\d+$/ 1 <= $option{"zone"} $option{"zone"} <= 32767
Truth table25%1/4
A and B and C
A= $option{"zone"} =~ /^\d+$/B= 1 <= $option{"zone"}C= $option{"zone"} <= 32767
ABCresult
0XX0
10X0
1100
1111
206  
207 2 $self{domain} = $option{domain};
208 2 $self{zone} = $option{zone};
209 }
210  
211 # domain abbreviations
212 2 ▶ if ( exists $option{domain_abbrev}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{'domain_abbrev'} and defined $option{'domain_abbrev'} and ref $option{'domain_abbrev'} eq 'HASH') { } 2 0 2
Condition33%2/6
exists $option{"domain_abbrev"} and defined $option{"domain_abbrev"} and ref $option{"domain_abbrev"} eq "HASH"
!ll&&!rl&&r
002
exists $option{"domain_abbrev"} and defined $option{"domain_abbrev"}
!ll&&!rl&&r
002
MC/DC0%0/3
exists $option{"domain_abbrev"} and defined $option{"domain_abbrev"} and ref $option{"domain_abbrev"} eq "HASH"
exists $option{"domain_abbrev"} defined $option{"domain_abbrev"} ref $option{"domain_abbrev"} eq "HASH"
Truth table25%1/4
A and B and C
A= exists $option{"domain_abbrev"}B= defined $option{"domain_abbrev"}C= ref $option{"domain_abbrev"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
213 && defined $option{domain_abbrev}
214 && ref $option{domain_abbrev} eq 'HASH'
215 ) {
216 $logger -> logdie( sprintf 'our domain (%s) is not in the passed domain_abbrev hash!',
217 $self{domain},
218 )
219 2 ▶ unless exists $option{domain_abbrev}{ $self{domain} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"domain_abbrev"}{$self{"domain"}} 0 2 2
220  
221 2 $self{domain_abbrev} = $option{domain_abbrev};
222 } else {
223 0 $logger -> logdie( 'no valid domain_abbrev provided' );
224 }
225  
226 # reference file read line transform sub
227 2 ▶ if ( exists $option{reference_file_read_line_transform_sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"reference_file_read_line_transform_sub"}) 0 2 2
228 $logger -> logdie( 'incorrect value of reference_file_read_line_transform_sub (should be a sub reference)' )
229 unless defined $option{reference_file_read_line_transform_sub}
230 0 ▶ && 'CODE' eq ref $option{reference_file_read_line_transform_sub};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $option{"reference_file_read_line_transform_sub"} and "CODE" eq ref $option{"reference_file_read_line_transform_sub"} 0 0 0
Condition0%0/3
defined $option{"reference_file_read_line_transform_sub"} and "CODE" eq ref $option{"reference_file_read_line_transform_sub"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $option{"reference_file_read_line_transform_sub"} and "CODE" eq ref $option{"reference_file_read_line_transform_sub"}
defined $option{"reference_file_read_line_transform_sub"} "CODE" eq ref $option{"reference_file_read_line_transform_sub"}
Truth table0%0/3
A and B
A= defined $option{"reference_file_read_line_transform_sub"}B= "CODE" eq ref $option{"reference_file_read_line_transform_sub"}
ABresult
0X0
100
111
231  
232 0 $self{reference_file_read_line_transform_sub} = $option{reference_file_read_line_transform_sub};
233 }
234  
235 # maximum_session_time
236 2 ▶ if ( exists $option{maximum_session_time} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"maximum_session_time"}) 0 2 2
237 $logger -> logdie( sprintf 'incorrect value of maximum_session_time: %s',
238 defined $option{maximum_session_time} ?
239 $option{maximum_session_time}
240 : 'undef'
241 )
242 unless defined $option{maximum_session_time}
243 && $option{maximum_session_time} =~ m/^\d+$/
244 0 ▶ && $option{maximum_session_time}; # cannot be 0
Branch: 2 branches
BranchTrueFalseTotal
unless defined $option{"maximum_session_time"} and $option{"maximum_session_time"} =~ /^\d+$/ and $option{"maximum_session_time"} 0 0 0
defined $option{'maximum_session_time'} ? : 0 0 0
Condition0%0/6
defined $option{"maximum_session_time"} and $option{"maximum_session_time"} =~ /^\d+$/ and $option{"maximum_session_time"}
!ll&&!rl&&r
000
defined $option{"maximum_session_time"} and $option{"maximum_session_time"} =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $option{"maximum_session_time"} and $option{"maximum_session_time"} =~ /^\d+$/ and $option{"maximum_session_time"}
defined $option{"maximum_session_time"} $option{"maximum_session_time"} =~ /^\d+$/ $option{"maximum_session_time"}
Truth table0%0/4
A and B and C
A= defined $option{"maximum_session_time"}B= $option{"maximum_session_time"} =~ /^\d+$/C= $option{"maximum_session_time"}
ABCresult
0XX0
10X0
1100
1111
245  
246 0 $self{maximum_session_time} = $option{maximum_session_time};
247 }
248  
249 2 bless \ %self, $class;
250 }
251  
252 sub _store {
253 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine _store: not called CC=12 SCAR=50.5
254  
255 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
256  
257 0 my ( $file_prop,
258 $ext,
259 $target,
260 $net,
261 $node,
262 $point,
263 ) = @_;
264  
265 0 my %ext_netmail_flavour = map { $flavour_extension{ $_ }[ 0 ] => $_ } keys %flavour_extension;
266 0 my %ext_reference_file_flavour = map { $flavour_extension{ $_ }[ 1 ] => $_ } keys %flavour_extension;
267 0 my %ext_control_file = reverse %control_file_extension;
268  
269 0 my $lc_ext = lc $ext;
270  
271 0 ▶ if ( exists $ext_netmail_flavour{ $lc_ext } ) { # netmail
Branch: 3 branches
BranchTrueFalseTotal
if (exists $ext_netmail_flavour{$lc_ext}) { } 0 0 0
elsif (exists $ext_reference_file_flavour{$lc_ext}) { } 0 0 0
elsif (exists $ext_control_file{$lc_ext}) { } 0 0 0
272 0 push @{ $target -> { $net }{ $node }{ $point }{netmail}{ $ext_netmail_flavour{ $lc_ext } } },
273 $file_prop;
274 } elsif ( exists $ext_reference_file_flavour{ $lc_ext } ) { # reference file
275 0 my $flavour = $ext_reference_file_flavour{ $lc_ext };
276 # referenced files
277 0 ▶ if ( $file_prop -> {size} # empty files are empty, right?
Branch: 1 branch
BranchTrueFalseTotal
if ($file_prop->{"size"} and exists $self->{"reference_file_read_line_transform_sub"}) 0 0 0
Condition0%0/3
$file_prop->{"size"} and exists $self->{"reference_file_read_line_transform_sub"}
!ll&&!rl&&r
000
MC/DC0%0/2
$file_prop->{"size"} and exists $self->{"reference_file_read_line_transform_sub"}
$file_prop->{"size"} exists $self->{"reference_file_read_line_transform_sub"}
Truth table0%0/3
A and B
A= $file_prop->{"size"}B= exists $self->{"reference_file_read_line_transform_sub"}
ABresult
0X0
100
111
278 && exists $self -> {reference_file_read_line_transform_sub}
279 ) {
280 $file_prop -> {referenced_files} =
281 FTN::Outbound::Reference_file
282 -> new( $file_prop -> {full_name},
283 $self -> {reference_file_read_line_transform_sub},
284 )
285 0 -> read_existing_file
286 -> referenced_files;
287 }
288  
289 0 push @{ $target -> { $net }{ $node }{ $point }{reference_file}{ $flavour } },
290 $file_prop;
291 } elsif ( exists $ext_control_file{ $lc_ext } ) {
292 0 ▶ my $age = $file_prop -> {mstat} ? time - $file_prop -> {mstat} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$file_prop->{'mstat'} ? : 0 0 0
293 0 ▶ if ( $ext_control_file{ $lc_ext } eq 'busy'
Branch: 1 branch
BranchTrueFalseTotal
if ($ext_control_file{$lc_ext} eq 'busy' and exists $self->{'maximum_session_time'} and $self->{'maximum_session_time'} * 2 < $age) { } 0 0 0
Condition0%0/6
$ext_control_file{$lc_ext} eq "busy" and exists $self->{"maximum_session_time"} and $self->{"maximum_session_time"} * 2 < $age
!ll&&!rl&&r
000
$ext_control_file{$lc_ext} eq "busy" and exists $self->{"maximum_session_time"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ext_control_file{$lc_ext} eq "busy" and exists $self->{"maximum_session_time"} and $self->{"maximum_session_time"} * 2 < $age
$ext_control_file{$lc_ext} eq "busy" exists $self->{"maximum_session_time"} $self->{"maximum_session_time"} * 2 < $age
Truth table0%0/4
A and B and C
A= $ext_control_file{$lc_ext} eq "busy"B= exists $self->{"maximum_session_time"}C= $self->{"maximum_session_time"} * 2 < $age
ABCresult
0XX0
10X0
1100
1111
294 && exists $self -> {maximum_session_time}
295 && $self -> {maximum_session_time} * 2 < $age
296 ) { # try to remove if maximum_session_time is defined and busy is older than it
297 $logger -> info( sprintf 'removing expired busy %s (%d seconds old)',
298 $file_prop -> {full_name},
299 0 $age,
300 );
301  
302 unlink Encode::encode( locale_fs => $file_prop -> {full_name} )
303 or $logger -> logdie( sprintf 'could not unlink %s: %s',
304 $file_prop -> {full_name},
305 0 ▶ $!,
Branch: 1 branch
BranchTrueFalseTotal
unlink &Encode::encode("locale_fs", $file_prop->{"full_name"}) or $logger->logdie(sprintf('could not unlink %s: %s', $file_prop->{"full_name"}, $!)) 0 0 0
306 );
307 } else {
308 0 push @{ $target -> { $net }{ $node }{ $point }{ $ext_control_file{ $lc_ext } } },
309 $file_prop;
310 }
311 }
312 }
313  
314 =head1 OBJECT METHODS
315  
316 =head2 scan
317  
318 Scans outbound for all known domains. Old busy files might be removed.
319  
320 Returns itself for chaining.
321  
322 =cut
323  
324 sub scan {
325 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine scan: not called CC=24 SCAR=64.0
Pod documented
326  
327 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
328  
329 $logger -> logdie( sprintf 'outbound_root (%s) directory does not exist',
330 $self -> {outbound_root},
331 )
332 0 ▶ unless -e $self -> {outbound_root_fs};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self->{"outbound_root_fs"} 0 0 0
333  
334 # if it exists it should be a directory
335 $logger -> logdie( sprintf 'outbound_root (%s) does not point to the directory',
336 $self -> {outbound_root},
337 )
338 0 ▶ unless -d _;
Branch: 1 branch
BranchTrueFalseTotal
unless -d _ 0 0 0
339  
340 # check outbound_root for all domain abbrevs and zones
341 0 my $domain_abbr_re = join '|', values %{ $self -> {domain_abbrev} };
342 0 my %result;
343  
344 opendir my $or_dh, $self -> {outbound_root_fs}
345 or $logger -> logdie( sprintf 'cannot opendir %s: %s',
346 $self -> {outbound_root},
347 0 ▶ $!,
Branch: 1 branch
BranchTrueFalseTotal
opendir my $or_dh, $self->{"outbound_root_fs"} or $logger->logdie(sprintf('cannot opendir %s: %s', $self->{"outbound_root"}, $!)) 0 0 0
348 );
349  
350 0 ▶ while ( my $dz_out = readdir $or_dh ) { # looking for domain abbreviations directories
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dz_out = readdir $or_dh)) 0 0 0
351 0 $dz_out = Encode::decode( locale_fs => $dz_out );
352  
353 next # skipping hidden files and ..
354 0 ▶ if '.' eq substr $dz_out, 0, 1;
Branch: 1 branch
BranchTrueFalseTotal
if "." eq substr($dz_out, 0, 1) 0 0 0
355  
356 my $dir_name = File::Spec -> catdir( $self -> {outbound_root},
357 0 $dz_out,
358 );
359  
360 0 my $dir_name_fs = Encode::encode( locale_fs => $dir_name );
361  
362 next # looking only for directories
363 0 ▶ unless -d $dir_name_fs;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir_name_fs 0 0 0
364  
365 # our_domain_dir, our_domain_dir.9999, other_domain.9999
366 next
367 unless $dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/i
368 && ( $1 eq $self -> {domain_abbrev}{ $self -> {domain} }
369 0 ▶ || defined $2
Branch: 1 branch
BranchTrueFalseTotal
unless $dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/i and $1 eq $self->{"domain_abbrev"}{$self->{"domain"}} || defined $2 0 0 0
Condition0%0/6
$dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/i and $1 eq $self->{"domain_abbrev"}{$self->{"domain"}} || defined $2
!ll&&!rl&&r
000
$1 eq $self->{"domain_abbrev"}{$self->{"domain"}} or defined $2
l!l&&r!l&&!r
000
MC/DC0%0/3
$dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/i and $1 eq $self->{"domain_abbrev"}{$self->{"domain"}} || defined $2
$dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/i $1 eq $self->{"domain_abbrev"}{$self->{"domain"}} defined $2
Truth table0%0/4
A and B or C
A= $dz_out =~ /^($domain_abbr_re)(?:\.([1-7]?[0-9a-f]{3}))?$/iB= $1 eq $self->{"domain_abbrev"}{$self->{"domain"}}C= defined $2
ABCresult
0XX0
1000
11X1
1011
370 );
371  
372 my ( $domain ) = grep $self -> {domain_abbrev}{ $_ } eq $1,
373 0 keys %{ $self -> {domain_abbrev} };
374  
375 0 ▶ my $zone = defined $2 ? hex $2 : $self -> {zone};
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 0 0
376  
377 next
378 0 ▶ unless 1 <= $zone && $zone <= 32767; # FRL-1002.001, frl-1028.002
Branch: 1 branch
BranchTrueFalseTotal
unless 1 <= $zone and $zone <= 32767 0 0 0
Condition0%0/3
1 <= $zone and $zone <= 32767
!ll&&!rl&&r
000
MC/DC0%0/2
1 <= $zone and $zone <= 32767
1 <= $zone $zone <= 32767
Truth table0%0/3
A and B
A= 1 <= $zoneB= $zone <= 32767
ABresult
0X0
100
111
379  
380 0 $logger -> debug( sprintf 'directory %s matches. domain: %s zone: %s',
381 $dz_out,
382 $domain,
383 $zone,
384 );
385  
386 0 $result{ $domain }{ $zone }{ $dz_out }{dir} = $dir_name;
387  
388 # now let's traverse found domain_abbrev[.zone] dir
389 0 ▶ opendir my $dz_dh, $dir_name_fs
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dz_dh, $dir_name_fs or $logger->logdie(sprintf('cannot opendir %s: %s', $dir_name, $!)) 0 0 0
390 or $logger -> logdie( sprintf 'cannot opendir %s: %s',
391 $dir_name,
392 $!,
393 );
394  
395 0 ▶ while ( readdir $dz_dh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readdir $dz_dh)) 0 0 0
396 0 $_ = Encode::decode( locale_fs => $_ );
397  
398 next
399 0 ▶ unless m/^([0-9a-f]{4})([0-9a-f]{4})\.(.+)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless /^([0-9a-f]{4})([0-9a-f]{4})\.(.+)$/i 0 0 0
400  
401 0 my ( $net, $node ) = map hex, $1, $2;
402 0 my $ext = $3;
403  
404 0 my $full_name = File::Spec -> catfile( $dir_name,
405 $_,
406 );
407  
408 0 my $full_name_fs = Encode::encode( locale_fs => $full_name );
409  
410 0 ▶ if ( lc( $ext ) eq 'pnt'
Branch: 2 branches
BranchTrueFalseTotal
if (lc $ext eq 'pnt' and -d $full_name_fs) { } 0 0 0
elsif (-f $full_name_fs) { } 0 0 0
Condition0%0/3
lc $ext eq "pnt" and -d $full_name_fs
!ll&&!rl&&r
000
MC/DC0%0/2
lc $ext eq "pnt" and -d $full_name_fs
lc $ext eq "pnt" -d $full_name_fs
Truth table0%0/3
A and B
A= lc $ext eq "pnt"B= -d $full_name_fs
ABresult
0X0
100
111
411 && -d $full_name_fs
412 ) { # points subdir
413 0 $logger -> debug( sprintf 'found %s#%d:%d/%d points subdirectory %s',
414 $domain,
415 $zone,
416 $net,
417 $node,
418 $full_name,
419 );
420  
421 0 $result{ $domain }{ $zone }{ $dz_out }{ $net }{ $node }{points_dir}{ $_ } = $full_name; # might be different hex casing for net/node or extension
422  
423 0 ▶ opendir my $p_dh, $full_name_fs
Branch: 1 branch
BranchTrueFalseTotal
opendir my $p_dh, $full_name_fs or $logger->logdie(sprintf('cannot opendir %s: %s', $full_name, $!)) 0 0 0
424 or $logger -> logdie( sprintf 'cannot opendir %s: %s',
425 $full_name,
426 $!,
427 );
428  
429 0 ▶ while ( my $file = readdir $p_dh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir $p_dh)) 0 0 0
430 0 $file = Encode::decode( locale_fs => $file );
431  
432 next
433 0 ▶ unless $file =~ m/^([0-9a-f]{8})\.(.+)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /^([0-9a-f]{8})\.(.+)$/i 0 0 0
434  
435 0 my $point = hex $1;
436 0 my $ext = $2;
437  
438 0 my $full_name = File::Spec -> catfile( $full_name,
439 $file,
440 );
441  
442 next # in points dir we're interested in files only
443 0 ▶ unless -f Encode::encode( locale_fs => $full_name );
Branch: 1 branch
BranchTrueFalseTotal
unless -f &Encode::encode("locale_fs", $full_name) 0 0 0
444  
445 $self -> _store( { name => $file,
446 full_name => $full_name,
447 size => -s _,
448 mstat => ( stat _ )[ 9 ],
449 },
450 $ext,
451 0 $result{ $domain }{ $zone }{ $dz_out },
452 $net,
453 $node,
454 $point,
455 );
456 }
457 0 closedir $p_dh;
458 } elsif ( -f $full_name_fs ) { # node related file
459 $self -> _store( { name => $_,
460 full_name => $full_name,
461 size => -s _,
462 mstat => ( stat _ )[ 9 ],
463 },
464 $ext,
465 0 $result{ $domain }{ $zone }{ $dz_out },
466 $net,
467 $node,
468 0, # point
469 );
470 }
471 }
472 0 closedir $dz_dh;
473  
474 }
475 0 closedir $or_dh;
476  
477 0 $self -> {scanned} = \ %result;
478  
479 0 $self;
480 }
481  
482 =head2 scanned_hash
483  
484 Returns internal structure representing scanned outbound (hash in list context, hashref in scalar context). If scan method hasn't been called, it will be called implicitly by this method.
485  
486 =cut
487  
488 sub scanned_hash {
489 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine scanned_hash: not called CC=4 SCAR=30.0
Pod documented
490  
491 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
492  
493 $self -> scan
494 0 ▶ unless exists $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"} 0 0 0
495  
496 wantarray ?
497 0 %{ $self -> {scanned} }
498 0 ▶ : $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
499 }
500  
501  
502 sub _validate_addr {
503 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine _validate_addr: not called CC=7 SCAR=40.3
504  
505 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
506  
507 0 my $addr = shift;
508  
509 0 ▶ $logger -> logdie( 'no valid address passed' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $addr and ref $addr and builtin::blessed($addr) and $addr->isa("FTN::Addr") 0 0 0
Condition0%0/9
defined $addr and ref $addr and builtin::blessed($addr) and $addr->isa("FTN::Addr")
!ll&&!rl&&r
000
defined $addr and ref $addr and builtin::blessed($addr)
!ll&&!rl&&r
000
defined $addr and ref $addr
!ll&&!rl&&r
000
MC/DC0%0/4
defined $addr and ref $addr and builtin::blessed($addr) and $addr->isa("FTN::Addr")
defined $addr ref $addr builtin::blessed($addr) $addr->isa("FTN::Addr")
Truth table0%0/5
A and B and C and D
A= defined $addrB= ref $addrC= builtin::blessed($addr)D= $addr->isa("FTN::Addr")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
510 unless defined $addr
511 && ref $addr
512 && Scalar::Util::blessed $addr
513 && $addr -> isa( 'FTN::Addr' );
514  
515 $logger -> logdie( 'passed address has unknown domain: %s',
516 $addr -> domain,
517 )
518 0 ▶ unless exists $self -> {domain_abbrev}{ $addr -> domain };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"domain_abbrev"}{$addr->domain} 0 0 0
519  
520 0 $addr;
521 }
522  
523 =head2 is_busy
524  
525 Expects one parameter - address as FTN::Addr object. Returns true if that address is busy (connection session, mail processing, ...).
526  
527 =cut
528  
529 sub is_busy {
530 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine is_busy: not called CC=8 SCAR=42.8
Pod documented
531  
532 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
533  
534 0 my $addr = $self -> _validate_addr( shift );
535  
536 $self -> scan
537 0 ▶ unless exists $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"} 0 0 0
538  
539 exists $self -> {scanned}{ $addr -> domain }
540 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }
541 && grep exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }
542 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }
543 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }
544 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }{busy},
545 0 ▶ keys %{ $self -> {scanned}{ $addr -> domain }{ $addr -> zone } };
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"scanned"}{$addr->domain} and exists $self->{"scanned"}{$addr->domain}{$addr->zone} and grep((exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} && exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} && exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} && exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{"busy"}), keys %{$self->{"scanned"}{$addr->domain}{$addr->zone};}) 0 0 0
Condition0%0/12
exists $self->{"scanned"}{$addr->domain} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}
!ll&&!rl&&r
000
exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{'busy'}
!ll&&!rl&&r
000
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}
!ll&&!rl&&r
000
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"scanned"}{$addr->domain} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}
exists $self->{"scanned"}{$addr->domain} exists $self->{"scanned"}{$addr->domain}{$addr->zone}
MC/DC0%0/4
exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{'busy'}
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{'busy'}
Truth table0%0/3
A and B
A= exists $self->{"scanned"}{$addr->domain}B= exists $self->{"scanned"}{$addr->domain}{$addr->zone}
ABresult
0X0
100
111
Truth table0%0/5
A and B and C && D
A= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}B= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}C= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}D= exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{'busy'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
546 }
547  
548 sub _select_domain_zone_dir { # best one. for updating. for checking need a list (another method or direct access to the structure)
549 # and make it if it doesn't exist or isn't good enough (e.g. our_domain_abbr.our_zone)
550 10 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine _select_domain_zone_dir: called CC=13 SCAR=30.0
551  
552 10 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 10 10
553  
554 10 my $domain = shift;
555 10 my $zone = shift;
556  
557 $logger -> logdie( 'unknown domain: %s',
558 $domain,
559 )
560 10 ▶ unless exists $self -> {domain_abbrev}{ $domain };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"domain_abbrev"}{$domain} 0 10 10
561  
562 10 my $best_match = $self -> {domain_abbrev}{ $domain };
563  
564 $best_match .= sprintf( '.%03x', $zone )
565 unless $domain eq $self -> {domain}
566 10 ▶ && $zone == $self -> {zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $domain eq $self->{"domain"} and $zone == $self->{"zone"} 4 6 10
Condition66%2/3
$domain eq $self->{"domain"} and $zone == $self->{"zone"}
!ll&&!rl&&r
046
MC/DC50%1/2
$domain eq $self->{"domain"} and $zone == $self->{"zone"}
$domain eq $self->{"domain"} $zone == $self->{"zone"}
Truth table66%2/3
A and B
A= $domain eq $self->{"domain"}B= $zone == $self->{"zone"}
ABresult
0X0
100
111
567  
568 $self -> scan
569 10 ▶ unless exists $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"} 0 10 10
570  
571 10 ▶ if ( exists $self -> {scanned}{ $domain }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'scanned'}{$domain} and exists $self->{'scanned'}{$domain}{$zone} and $domain ne $self->{'domain'} || $zone != $self->{'zone'} || grep((length $_ == length $best_match), keys %{$$self{'scanned'}{$domain}{$zone};})) { } 10 0 10
Condition50%6/12
exists $self->{"scanned"}{$domain} and exists $self->{"scanned"}{$domain}{$zone} and $domain ne $self->{"domain"} || $zone != $self->{"zone"} || grep((length $_ == length $best_match), keys %{$$self{"scanned"}{$domain}{$zone};})
!ll&&!rl&&r
0010
exists $self->{"scanned"}{$domain} and exists $self->{"scanned"}{$domain}{$zone}
!ll&&!rl&&r
0010
$domain ne $self->{"domain"} or $zone != $self->{"zone"} or grep((length $_ == length $best_match), keys %{$$self{"scanned"}{$domain}{$zone};})
l!l&&r!l&&!r
460
$domain ne $self->{"domain"} or $zone != $self->{"zone"}
l!l&&r!l&&!r
046
MC/DC0%0/5
exists $self->{"scanned"}{$domain} and exists $self->{"scanned"}{$domain}{$zone} and $domain ne $self->{"domain"} || $zone != $self->{"zone"} || grep((length $_ == length $best_match), keys %{$$self{"scanned"}{$domain}{$zone};})
exists $self->{"scanned"}{$domain} exists $self->{"scanned"}{$domain}{$zone} $domain ne $self->{"domain"} $zone != $self->{"zone"} grep((length $_ == length $best_match), keys %{$$self{"scanned"}{$domain}{$zone};})
Truth table33%2/6
A and B and C or D or E
A= exists $self->{"scanned"}{$domain}B= exists $self->{"scanned"}{$domain}{$zone}C= $domain ne $self->{"domain"}D= $zone != $self->{"zone"}E= grep((length $_ == length $best_match), keys %{$$self{"scanned"}{$domain}{$zone};})
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
572 && exists $self -> {scanned}{ $domain }{ $zone }
573 && ( $domain ne $self -> {domain} # other domains have zones in extensions
574 || $zone != $self -> {zone} # other zones in our domain have zones in extensions
575 || grep length( $_ ) == length( $best_match ),
576 6 keys %{ $self -> {scanned}{ $domain }{ $zone } }
577 )
578 ) {
579 27 my @list = sort { length $a <=> length $b }
580 10 keys %{ $self -> {scanned}{ $domain }{ $zone } };
581  
582 10 my ( $t ) = grep $_ eq $best_match, @list; # might be exact case
583  
584 10 ▶ $best_match = defined $t ?
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 8 2 10
585 $t
586 : $list[ 0 ]; # if didn't find the best match, use very first existing
587 } else { # need to create
588 my $dir_full_name = File::Spec -> catdir( $self -> {outbound_root},
589 0 $best_match,
590 );
591  
592 0 $logger -> debug( sprintf 'creating directory for domain %s zone %d: %s',
593 $domain,
594 $zone,
595 $dir_full_name,
596 );
597  
598 0 ▶ mkdir Encode::encode( locale_fs => $dir_full_name )
Branch: 1 branch
BranchTrueFalseTotal
mkdir &Encode::encode("locale_fs", $dir_full_name) or $logger->logdie(sprintf('cannot create domain/zone %s directory: %s', $dir_full_name, $!)) 0 0 0
599 or $logger -> logdie( sprintf 'cannot create domain/zone %s directory: %s',
600 $dir_full_name,
601 $!,
602 );
603  
604 0 $self -> {scanned}{ $domain }{ $zone }{ $best_match }{dir} = $dir_full_name;
605 }
606  
607 # $self -> {scanned}{ $domain }{ $zone }{ $best_match }{dir};
608 10 $best_match;
609 }
610  
611 sub _select_points_dir { # select best existing. or make it. for updating
612 6 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine _select_points_dir: called CC=10 SCAR=25.6
613  
614 6 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 6 6
615  
616 6 my ( $domain,
617 $zone,
618 $net,
619 $node,
620 ) = @_;
621  
622 $logger -> logdie( 'unknown domain: %s',
623 $domain,
624 )
625 6 ▶ unless exists $self -> {domain_abbrev}{ $domain };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"domain_abbrev"}{$domain} 0 6 6
626  
627 # domain zone dir might not exist at all
628 6 my $dz_out = $self -> _select_domain_zone_dir( $domain, $zone );
629 6 my $points_dir = sprintf( '%04x%04x.pnt',
630 $net,
631 $node,
632 );
633  
634 # what if other_domain_abbr.zone (perfect one) doesn't have required points dir
635 # but other_domain_abbr.zOnE has?
636 my @dz_out_with_existing_points_dir = grep exists $self -> {scanned}{ $domain }{ $zone }{ $_ }{ $net }
637 && exists $self -> {scanned}{ $domain }{ $zone }{ $_ }{ $net }{ $node }
638 && exists $self -> {scanned}{ $domain }{ $zone }{ $_ }{ $net }{ $node }{points_dir},
639 grep length $_ == length $dz_out, # to filter out our_domain.our_zone versions
640 6 ▶ keys %{ $self -> {scanned}{ $domain }{ $zone } };
Condition66%4/6
exists $self->{'scanned'}{$domain}{$zone}{$_}{$net} && exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node} && exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node}{'points_dir'}
!ll&&!rl&&r
909
exists $self->{"scanned"}{$domain}{$zone}{$_}{$net} and exists $self->{"scanned"}{$domain}{$zone}{$_}{$net}{$node}
!ll&&!rl&&r
909
MC/DC33%1/3
exists $self->{'scanned'}{$domain}{$zone}{$_}{$net} && exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node} && exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node}{'points_dir'}
exists $self->{"scanned"}{$domain}{$zone}{$_}{$net} exists $self->{"scanned"}{$domain}{$zone}{$_}{$net}{$node} exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node}{'points_dir'}
Truth table50%2/4
A and B && C
A= exists $self->{"scanned"}{$domain}{$zone}{$_}{$net}B= exists $self->{"scanned"}{$domain}{$zone}{$_}{$net}{$node}C= exists $self->{'scanned'}{$domain}{$zone}{$_}{$net}{$node}{'points_dir'}
ABCresult
0XX0
10X0
1100
1111
641  
642 6 ▶ if ( @dz_out_with_existing_points_dir ) { # ok, there is at least one with points dir. how do we select best of them?
Branch: 1 branch
BranchTrueFalseTotal
if (@dz_out_with_existing_points_dir) { } 6 0 6
643 # let's prioritize domain_abbr[.zone] betterness over points_dir betterness
644 6 ▶ unless ( grep $_ eq $dz_out,
Branch: 1 branch
BranchTrueFalseTotal
unless (grep(($_ eq $dz_out), @dz_out_with_existing_points_dir)) 5 1 6
645 @dz_out_with_existing_points_dir
646 ) { # ok, there is no best domain_abbr[.zone]. let's try to find best points_dir
647 5 my ( $t ) = grep exists $self -> {scanned}{ $domain }{ $zone }{ $_ }{ $net }{ $node }{points_dir}{ $points_dir },
648 @dz_out_with_existing_points_dir;
649  
650 5 ▶ $dz_out = defined $t ? $t : $dz_out_with_existing_points_dir[ 0 ]; # if no best in either place, just use very first one
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 5 0 5
651 }
652  
653 # now we've got best outbound. let's find best points dir. or just very first
654 1 $points_dir = ( keys %{ $self -> {scanned}{ $domain }{ $zone }{ $dz_out }{ $net }{ $node }{points_dir} } )[ 0 ]
655 6 ▶ unless exists $self -> {scanned}{ $domain }{ $zone }{ $dz_out }{ $net }{ $node }{points_dir}{ $points_dir };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"}{$domain}{$zone}{$dz_out}{$net}{$node}{"points_dir"}{$points_dir} 1 5 6
656  
657 } else { # doesn't exist. we need to create it using best domain_abbr[.zone] dir
658 my $dir_full_name = File::Spec -> catdir( $self -> {scanned}{ $domain }{ $zone }{ $dz_out }{dir},
659 0 $points_dir,
660 );
661  
662 0 $logger -> debug( sprintf 'creating %s#%d:%d/%d points directory %s',
663 $domain,
664 $zone,
665 $net,
666 $node,
667 $dir_full_name,
668 );
669  
670 0 ▶ mkdir Encode::encode( locale_fs => $dir_full_name )
Branch: 1 branch
BranchTrueFalseTotal
mkdir &Encode::encode("locale_fs", $dir_full_name) or $logger->logdie(sprintf('cannot create points directory %s: %s', $dir_full_name, $!)) 0 0 0
671 or $logger -> logdie( sprintf 'cannot create points directory %s: %s',
672 $dir_full_name,
673 $!,
674 );
675  
676 0 $self -> {scanned}{ $domain }{ $zone }{ $dz_out }{ $net }{ $node }{points_dir}{ $points_dir } = $dir_full_name;
677 }
678  
679 # return ( dz_out, $points_dir) or full points directory path?
680 6 $self -> {scanned}{ $domain }{ $zone }{ $dz_out }{ $net }{ $node }{points_dir}{ $points_dir };
681 }
682  
683 =head2 busy_protected_sub
684  
685 Expects two parameters:
686  
687 address going to be dealt with as a FTN::Addr object
688  
689 function reference that will receive passed address and us ($self) as parameters and which should do all required operations related to the passed address.
690  
691 This method infinitely waits (most likely will be changed in the future) until address is not busy. Then it creates busy flag and calls passed function reference providing itself as an argument for it. After function return removes created busy flag.
692  
693 Returns itself for chaining.
694  
695 =cut
696  
697 sub busy_protected_sub { # address, sub_ref( self ). (order busy, execute sub, remove busy)
698 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine busy_protected_sub: not called CC=12 SCAR=50.5
Pod documented
699  
700 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
701  
702 0 my $addr = $self -> _validate_addr( shift );
703  
704 0 ▶ $logger -> logdie( 'no valid sub_ref passed' )
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] and "CODE" eq ref $_[0] 0 0 0
Condition0%0/6
@_ and defined $_[0] and "CODE" eq ref $_[0]
!ll&&!rl&&r
000
@_ and defined $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@_ and defined $_[0] and "CODE" eq ref $_[0]
@_ defined $_[0] "CODE" eq ref $_[0]
Truth table0%0/4
A and B and C
A= @_B= defined $_[0]C= "CODE" eq ref $_[0]
ABCresult
0XX0
10X0
1100
1111
705 unless @_
706 && defined $_[ 0 ]
707 && 'CODE' eq ref $_[ 0 ];
708  
709 0 my $sub_ref = shift;
710  
711 $self -> scan
712 0 ▶ unless exists $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"} 0 0 0
713  
714 # check that it's not already busy
715 0 ▶ while ( $self -> is_busy( $addr ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_busy($addr)) 0 0 0
716 0 sleep( 4 ); # blocking...
717 0 $self -> scan;
718 }
719  
720 # here there are no busy flag for passed address. make it in best dir then
721 0 my $busy_name;
722  
723 0 ▶ if ( $addr -> point ) { # possible dir creation
Branch: 1 branch
BranchTrueFalseTotal
if ($addr->point) { } 0 0 0
724 0 $busy_name = File::Spec -> catfile( $self -> _select_points_dir( $addr -> domain,
725 $addr -> zone,
726 $addr -> net,
727 $addr -> node,
728 ),
729 sprintf( '%08x',
730 $addr -> point,
731 ),
732 );
733 } else {
734 0 my $dz_out = $self -> _select_domain_zone_dir( $addr -> domain,
735 $addr -> zone,
736 );
737  
738 $busy_name = File::Spec -> catfile( $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $dz_out }{dir},
739 0 sprintf( '%04x%04x',
740 $addr -> net,
741 $addr -> node,
742 ),
743 );
744 }
745 0 $busy_name .= '.' . $control_file_extension{busy};
746  
747 0 my $busy_name_fs = Encode::encode( locale_fs => $busy_name );
748  
749 0 ▶ sysopen my $fh, $busy_name_fs, Fcntl::O_WRONLY | Fcntl::O_CREAT | Fcntl::O_EXCL
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $busy_name_fs, 193 or $logger->logdie("cannot open %s for writing: %s", $busy_name, $!) 0 0 0
750 or $logger -> logdie( 'cannot open %s for writing: %s',
751 $busy_name,
752 $!,
753 );
754  
755 0 ▶ flock $fh, Fcntl::LOCK_EX
Branch: 1 branch
BranchTrueFalseTotal
flock $fh, 2 or $logger->logdie("can't flock file %s: %s", $busy_name, $!) 0 0 0
756 or $logger -> logdie( q[can't flock file %s: %s],
757 $busy_name,
758 $!
759 );
760  
761 # For information purposes a bsy file may contain one line of PID information (less than 70 characters).
762 0 printf $fh '%d %s',
763 $$,
764 substr( __FILE__, 0, 70 - 1 - length( $$ ) );
765  
766 0 eval {
767 0 $sub_ref -> ( $addr,
768 $self,
769 );
770 };
771  
772 # remove busy first
773 0 close $fh;
774  
775 0 ▶ unlink $busy_name_fs
Branch: 1 branch
BranchTrueFalseTotal
unlink $busy_name_fs or $logger->logwarn(sprintf('could not unlink %s: %s', $busy_name, $!)) 0 0 0
776 or $logger -> logwarn( sprintf 'could not unlink %s: %s',
777 $busy_name,
778 $!,
779 );
780  
781 0 ▶ if ( $@ ) { # something bad happened
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
782 0 $logger -> logdie( 'referenced sub execution failed: %s',
783 $@,
784 );
785 }
786  
787 0 $self;
788 }
789  
790 =head2 addr_file_to_change
791  
792 Expects arguments:
793  
794 address going to be dealt with as a FTN::Addr object
795  
796 file type as one of netmail, reference_file, file_request, busy, call, hold, try.
797  
798 If file type is netmail or reference_file, then next parameter should be its flavour: immediate, crash, direct, normal, hold.
799  
800 If optional function reference passed, then it will be called with one parameter - name of the file to process. After that information in internal structure about that file will be updated.
801  
802 Does not deal with busy flag implicitly. Recommended usage is in the function passed to busy_protected_sub.
803  
804 Returns full name of the file to process (might not exists though).
805  
806 =cut
807  
808 sub addr_file_to_change { # addr, type ( netmail, file_reference, .. ), [flavour], [ sub_ref( filename ) ].
809 # figures required filetype name (new or existing) and calls subref with that name.
810 # does not deal with busy implicitly
811 # returns full name of changed file (might not exist though)
812 0 ▶ my $logger = Log::Log4perl -> get_logger( __PACKAGE__ );
Subroutine addr_file_to_change: not called CC=38 SCAR=73.0
Pod documented
813  
814 0 ▶ ref( my $self = shift ) or $logger -> logcroak( "I'm only an object method!" );
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or $logger->logcroak("I'm only an object method!") 0 0 0
815  
816 0 my $addr = $self -> _validate_addr( shift );
817  
818 0 my @flavoured = qw/ netmail
819 reference_file
820 /;
821  
822 0 ▶ $logger -> logdie( 'no type passed' )
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
823 unless @_;
824  
825 0 ▶ $logger -> logdie( sprintf 'incorrect type: %s',
Branch: 2 branches
BranchTrueFalseTotal
unless defined $_[0] and grep(($_[0] eq $_), @flavoured, keys %control_file_extension) 0 0 0
defined $_[0] ? : 0 0 0
Condition0%0/3
defined $_[0] and grep(($_[0] eq $_), @flavoured, keys %control_file_extension)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and grep(($_[0] eq $_), @flavoured, keys %control_file_extension)
defined $_[0] grep(($_[0] eq $_), @flavoured, keys %control_file_extension)
Truth table0%0/3
A and B
A= defined $_[0]B= grep(($_[0] eq $_), @flavoured, keys %control_file_extension)
ABresult
0X0
100
111
826 defined $_[ 0 ] ? $_[ 0 ] : 'undef',
827 )
828 unless defined $_[ 0 ]
829 && grep $_[ 0 ] eq $_,
830 @flavoured,
831 keys %control_file_extension;
832  
833 0 my $type = shift;
834  
835 0 ▶ my $filename = $addr -> point ?
Branch: 1 branch
BranchTrueFalseTotal
$addr->point ? : 0 0 0
836 sprintf( '%08x.', $addr -> point )
837 : sprintf( '%04x%04x.',
838 $addr -> net,
839 $addr -> node,
840 );
841  
842 0 my $flavoured = grep $type eq $_, @flavoured;
843 0 my $flavour;
844 0 ▶ if ( $flavoured ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flavoured) { } 0 0 0
845 0 ▶ $logger -> logdie( 'no flavour passed' )
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
846 unless @_;
847  
848 0 $flavour = shift;
849  
850 $logger -> logdie( sprintf 'incorrect flavour: %s',
851 defined $flavour ? $flavour : 'undef',
852 )
853 unless defined $flavour
854 0 ▶ && exists $flavour_extension{ $flavour };
Branch: 2 branches
BranchTrueFalseTotal
unless defined $flavour and exists $flavour_extension{$flavour} 0 0 0
defined $flavour ? : 0 0 0
Condition0%0/3
defined $flavour and exists $flavour_extension{$flavour}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flavour and exists $flavour_extension{$flavour}
defined $flavour exists $flavour_extension{$flavour}
Truth table0%0/3
A and B
A= defined $flavourB= exists $flavour_extension{$flavour}
ABresult
0X0
100
111
855  
856 $filename .= $type eq $flavoured[ 0 ] ? # netmail
857 $flavour_extension{ $flavour }[ 0 ]
858 0 ▶ : $flavour_extension{ $flavour }[ 1 ];
Branch: 1 branch
BranchTrueFalseTotal
$type eq $flavoured[0] ? : 0 0 0
859 } else {
860 0 $filename .= $control_file_extension{ $type };
861 }
862  
863 0 my $sub_ref;
864  
865 0 ▶ if ( @_ ) { # possible sub ref
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
866 0 ▶ $logger -> logdie( 'no valid sub_ref passed' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and "CODE" eq ref $_[0] 0 0 0
Condition0%0/3
defined $_[0] and "CODE" eq ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and "CODE" eq ref $_[0]
defined $_[0] "CODE" eq ref $_[0]
Truth table0%0/3
A and B
A= defined $_[0]B= "CODE" eq ref $_[0]
ABresult
0X0
100
111
867 unless defined $_[ 0 ]
868 && 'CODE' eq ref $_[ 0 ];
869  
870 0 $sub_ref = shift;
871 }
872  
873  
874 $self -> scan
875 0 ▶ unless exists $self -> {scanned};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scanned"} 0 0 0
876  
877  
878 # check any outdir except our_domain.our_zone for already existing file
879 0 my $dz_out = $self -> _select_domain_zone_dir( $addr -> domain, $addr -> zone );
880  
881 my @dz_out_with_existing_file = grep exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }
882 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }
883 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }
884 && exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type }
885 && ( ! $flavoured
886 || exists $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type }{ $flavour }
887 ),
888 grep length $_ == length $dz_out, # to filter out our_domain.our_zone versions
889 0 ▶ keys %{ $self -> {scanned}{ $addr -> domain }{ $addr -> zone } };
Condition0%0/15
exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type} && (!$flavoured || exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}{$flavour})
!ll&&!rl&&r
000
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}
!ll&&!rl&&r
000
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}
!ll&&!rl&&r
000
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} and exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}
!ll&&!rl&&r
000
not $flavoured or exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}{$flavour}
l!l&&r!l&&!r
000
MC/DC0%0/6
exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} && exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type} && (!$flavoured || exists $self->{'scanned'}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}{$flavour})
exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net} exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node} exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point} exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type} not $flavoured exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}{$flavour}
Truth table0%0/7
A and B and C and D && not(E) or F
A= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}B= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}C= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}D= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}E= not $flavouredF= exists $self->{"scanned"}{$addr->domain}{$addr->zone}{$_}{$addr->net}{$addr->node}{$addr->point}{$type}{$flavour}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
890  
891 0 my $full_filename;
892  
893 0 ▶ if ( @dz_out_with_existing_file ) { # file exists
Branch: 1 branch
BranchTrueFalseTotal
if (@dz_out_with_existing_file) { } 0 0 0
894 0 ▶ unless ( grep $dz_out eq $_,
Branch: 1 branch
BranchTrueFalseTotal
unless (grep(($dz_out eq $_), @dz_out_with_existing_file)) 0 0 0
895 @dz_out_with_existing_file
896 ) { # best domain.zone does not have existing file. let's select best of the worst
897 # first try to find one with best formatted file
898 my ( $t ) = grep {
899 0 my $r = $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $_ }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type };
900  
901 0 ▶ $r = $r -> { $flavour }
Branch: 1 branch
BranchTrueFalseTotal
if $flavoured 0 0 0
902 if $flavoured;
903  
904 grep $filename eq $_ -> {name},
905 0 @$r;
906 } @dz_out_with_existing_file;
907  
908 0 ▶ $dz_out = $t ? $t : $dz_out_with_existing_file[ 0 ]; # or just very first one
Branch: 1 branch
BranchTrueFalseTotal
$t ? : 0 0 0
909 }
910  
911 # here we've got dz_out with existing file
912 0 my $r = $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $dz_out }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type };
913  
914 0 ▶ $r = $r -> { $flavour }
Branch: 1 branch
BranchTrueFalseTotal
if $flavoured 0 0 0
915 if $flavoured;
916  
917 $filename = $r -> [ 0 ]{name}
918 unless grep $filename eq $_ -> {name}, # no best file name
919 0 ▶ @$r;
Branch: 1 branch
BranchTrueFalseTotal
unless grep(($filename eq $_->{"name"}), @$r) 0 0 0
920  
921 ( $full_filename ) = map $_ -> {full_name},
922 grep $filename eq $_ -> {name},
923 0 @$r;
924  
925 # and remove it..
926 0 @$r = grep $filename ne $_ -> {name}, @$r;
927 } else { # no file - create it
928 $full_filename = File::Spec -> catfile( $addr -> point ?
929 $self -> _select_points_dir( $addr -> domain,
930 $addr -> zone,
931 $addr -> net,
932 $addr -> node,
933 )
934 : $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $dz_out }{dir},
935 0 ▶ $filename,
Branch: 1 branch
BranchTrueFalseTotal
$addr->point ? : 0 0 0
936 );
937 }
938  
939 0 ▶ if ( $sub_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_ref) 0 0 0
940 0 eval {
941 0 $sub_ref -> ( $full_filename );
942 };
943  
944 0 ▶ if ( $@ ) { # something bad happened
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
945 0 $logger -> logdie( sprintf 'referenced sub execution failed: %s',
946 $@,
947 );
948 }
949  
950 # update file information in internal structure
951 # first remove existing record about file (if it's known)
952 {
953 0 my $r = $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $dz_out }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type };
954  
955 0 ▶ $r = $r -> { $flavour }
Branch: 1 branch
BranchTrueFalseTotal
if $flavoured 0 0 0
956 if $flavoured;
957  
958 0 my ( $record_idx ) = grep $_ -> {full_name} eq $full_filename, 0 .. $#$r;
959 0 ▶ splice @$r, $record_idx, 1
Branch: 1 branch
BranchTrueFalseTotal
if defined $record_idx 0 0 0
960 if defined $record_idx;
961  
962 # might be a good idea to remove empty parents as well if there was just one file
963 }
964  
965 0 ▶ if ( -e Encode::encode( locale_fs => $full_filename ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e &Encode::encode("locale_fs", $full_filename)) 0 0 0
966 0 my $r = $self -> {scanned}{ $addr -> domain }{ $addr -> zone }{ $dz_out }{ $addr -> net }{ $addr -> node }{ $addr -> point }{ $type };
967  
968 0 ▶ $r = $r -> { $flavour }
Branch: 1 branch
BranchTrueFalseTotal
if $flavoured 0 0 0
969 if $flavoured;
970  
971 0 my %file_prop = ( name => $filename,
972 full_name => $full_filename,
973 mstat => ( stat _ )[ 9 ],
974 size => -s _,
975 );
976  
977 $file_prop{referenced_files} =
978 FTN::Outbound::Reference_file
979 -> new( $file_prop{full_name},
980 $self -> {reference_file_read_line_transform_sub},
981 )
982 -> read_existing_file
983 -> referenced_files
984 if $type eq 'reference_file'
985 && $file_prop{size} # empty files are empty, right?
986 0 ▶ && exists $self -> {reference_file_read_line_transform_sub};
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "reference_file" and $file_prop{"size"} and exists $self->{"reference_file_read_line_transform_sub"} 0 0 0
Condition0%0/6
$type eq "reference_file" and $file_prop{"size"} and exists $self->{"reference_file_read_line_transform_sub"}
!ll&&!rl&&r
000
$type eq "reference_file" and $file_prop{"size"}
!ll&&!rl&&r
000
MC/DC0%0/3
$type eq "reference_file" and $file_prop{"size"} and exists $self->{"reference_file_read_line_transform_sub"}
$type eq "reference_file" $file_prop{"size"} exists $self->{"reference_file_read_line_transform_sub"}
Truth table0%0/4
A and B and C
A= $type eq "reference_file"B= $file_prop{"size"}C= exists $self->{"reference_file_read_line_transform_sub"}
ABCresult
0XX0
10X0
1100
1111
987  
988 0 push @$r, \ %file_prop;
989 }
990 }
991  
992 # what to return - just full name or open handle? handle probably better (can update scanned structure, but buffered/unbuffered? access details?)
993 # let's try full name first
994 0 $full_filename;
995 }
996  
997 3 1;
↑ Summary