TaskPipe/PortManager.pm

filter: Statementstmt 45.2% 19 / 42 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 3 totaltotal 39.3% 24 / 61 CC 4 SCAR 15.1
CC
4
Cov
40%
get_new_port_number
12.0
get_port
6.0
__ANON__
2.0
CRAP 4.5
« TaskPipe/InterpParam/MatchHandler_name.pm ↑ Summary TaskPipe/InterpParam/MatchHandler_this.pm »
1 package TaskPipe::PortManager;
2  
3 40 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use Net::EmptyPort;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 has base_port => (is => 'rw', isa => 'Int');
9 40 has process_name => (is => 'rw', isa => 'Str');
10  
11 40 has gm => (is => 'rw', isa => 'TaskPipe::SchemaManager');
12 has run_info => (is => 'rw', isa => 'TaskPipe::RunInfo', default => sub{
13 1 ▶ TaskPipe::RunInfo->new
Subroutine __ANON__: called CC=1 SCAR=0.0
14 40 });
15  
16  
17 sub get_new_port_number{
18 0 ▶ my $self = shift;
Subroutine get_new_port_number: not called CC=3 SCAR=24.8
Pod undocumented
19  
20 0 my $err;
21 my $port;
22 0 my $base_port = $self->base_port;
23 0 my $port_row;
24 0 my $success = 0;
25  
26 0 ▶ while ( ! $success ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
27  
28 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$port_row->in_storage and do { do { $port = Net::EmptyPort::empty_port($base_port); $port_row = $self->gm->table("port")->find_or_new({"port", $port}, {"key", "primary"}); $base_port = $port + 1 } } 0 0 0
29 0 $port = Net::EmptyPort::empty_port( $base_port );
30 0 $port_row = $self->gm->table('port')->find_or_new({
31 port => $port,
32 }, {
33 key => 'primary'
34 });
35 0 $base_port = $port + 1;
36 } while( $port_row->in_storage );
37  
38 try {
39  
40 0 ▶ $port_row->insert;
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 $port_row->update({
42 job_id => $self->run_info->job_id,
43 thread_id => $self->run_info->thread_id,
44 process_name => $self->process_name
45 });
46 0 $success = 1;
47  
48 } catch {
49  
50 0 ▶ $base_port = $port + 1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 $success = 0;
52  
53 0 };
54
55 }
56  
57 0 return $port;
58 }
59  
60  
61 sub get_port{
62 0 ▶ my ($self) = @_;
Subroutine get_port: not called CC=2 SCAR=17.9
Pod undocumented
63  
64 0 my $port_row = $self->gm->table('port')->find({
65 job_id => $self->run_info->job_id,
66 process_name => $self->process_name,
67 thread_id => $self->run_info->thread_id
68 });
69  
70 0 ▶ return $port_row->port if $port_row;
Branch: 1 branch
BranchTrueFalseTotal
if $port_row 0 0 0
71 0 return +$self->get_new_port_number;
72 }
73  
74  
75  
76  
77 sub clear_ports{
78 0 ▶ my ($self,$job_id) = @_;
Subroutine clear_ports: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 0 my $ports_rs = $self->gm->table('port')->search({
81 job_id => $job_id
82 })->delete_all;
83  
84 }
85  
86 =head1 NAME
87  
88 TaskPipe::PortManager - manage ports for TaskPipe
89  
90 =head1 DESCRIPTION
91  
92 It is not recommended to use this module directly. See the general manpages for TaskPipe.
93  
94 =head1 AUTHOR
95  
96 Tom Gracey <tomgracey@gmail.com>
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 Copyright (c) Tom Gracey 2018
101  
102 TaskPipe is free software, licensed under
103  
104 The GNU Public License Version 3
105  
106 =cut
107  
108 40 __PACKAGE__->meta->make_immutable;
109 40 1;
« TaskPipe/InterpParam/MatchHandler_name.pm ↑ Summary TaskPipe/InterpParam/MatchHandler_this.pm »