| 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
MC/DC0%0/2
shift() || 'Ubic'->root_service
shift()
'Ubic'->root_service
Truth table0%0/3
A || B
A= shift()B= 'Ubic'->root_service
| |||||||||||||||||||||
| 31 | 0 | for $_ ($service->services) { | |||||||||||||||||||
| 32 | 0 | ▶ | if ($_->isa('Ubic::Multiservice')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 66 | 0 | my @names = @{ $portmap->{$port} }; | |||||||||||||||||||
| 67 | 0 | ▶ | while (my $name = shift @names) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | ▶ | return $name unless @names; # return last service even if it's disabled | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | ▶ | return $name if Ubic->is_enabled($name); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 1 | 1; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||