lib/Ubic/PortMap.pm

filter: Statementstmt 40.3% 23 / 57 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 100% 2 / 2 totaltotal 35.1% 32 / 91 SCAR 39.2
CC
11
Cov
31%
port2name
30.0
__ANON__
20.0
update
12.0
CRAP 50.6
« blib/lib/Ubic/PortMap.pm ↑ Summary bin/ubic-periodic »
1 package Ubic::PortMap;
2 1 $Ubic::PortMap::VERSION = '1.59';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: update and read mapping of ports to service names.
7  
8  
9 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Ubic::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Ubic::Persistent;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Ubic;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub _portmap_file {
17 0 ▶ my $ubic_dir = Ubic->get_data_dir;
Subroutine _portmap_file: not called CC=1 SCAR=6.9
18 0 my $PORTMAP_FILE = $ubic_dir.'/portmap';
19 0 return $PORTMAP_FILE;
20 }
21  
22 sub update {
23 0 ▶ validate_pos(@_);
Subroutine update: not called CC=3 SCAR=24.8
Pod documented
24  
25 0 my $portmap = Ubic::Persistent->new(_portmap_file());
26 0 my %port2service;
27  
28 my $process_tree;
29 $process_tree = sub {
30 0 ▶ my $service = shift() || Ubic->root_service;
Subroutine __ANON__: not called CC=4 SCAR=30.0
Condition0%0/3
shift() || 'Ubic'->root_service
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || 'Ubic'->root_service
shift() 'Ubic'->root_service
Truth table0%0/3
A || B
A= shift()B= 'Ubic'->root_service
ABresult
1X1
011
000
31 0 for $_ ($service->services) {
32 0 ▶ if ($_->isa('Ubic::Multiservice')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->isa('Ubic::Multiservice')) { } 0 0 0
33 # multiservice
34 0 $process_tree->($_);
35 }
36 else {
37 try {
38 0 ▶ my $port = $_->port;
Subroutine __ANON__: not called CC=2 SCAR=17.9
39 0 ▶ if ($port) {
Branch: 1 branch
BranchTrueFalseTotal
if ($port) 0 0 0
40 0 push @{ $portmap->{$port} }, $_->full_name;
41 }
42 }
43 catch {
44 0 ▶ ERROR $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 };
46 }
47 }
48 0 return;
49 0 };
50  
51 0 for (keys %{$portmap}) {
52 0 ▶ next unless /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^\d+$/ 0 0 0
53 0 delete $portmap->{$_};
54 }
55 0 $process_tree->();
56 0 $portmap->commit();
57 0 undef $portmap; # fighting memory leaks - closure doesn't allow local variable to be destroyed
58  
59 0 return;
60 }
61  
62 sub port2name($) {
63 0 ▶ my ($port) = validate_pos(@_, { regex => qr/^\d+$/ });
Subroutine port2name: not called CC=5 SCAR=34.0
Pod documented
64 0 my $portmap = Ubic::Persistent->load(_portmap_file());
65 0 ▶ return unless $portmap->{$port};
Branch: 1 branch
BranchTrueFalseTotal
unless $portmap->{$port} 0 0 0
66 0 my @names = @{ $portmap->{$port} };
67 0 ▶ while (my $name = shift @names) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = shift @names) 0 0 0
68 0 ▶ return $name unless @names; # return last service even if it's disabled
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 0 0
69 0 ▶ return $name if Ubic->is_enabled($name);
Branch: 1 branch
BranchTrueFalseTotal
if "Ubic"->is_enabled($name) 0 0 0
70 }
71 }
72  
73  
74 1 1;
75  
76 __END__
« blib/lib/Ubic/PortMap.pm ↑ Summary bin/ubic-periodic »