SDK/AppConfiguration/CreateSnapshotOperation.pm

filter: Statementstmt 100% 66 / 66 Branchbran 54.5% 24 / 44 Conditioncond 48.8% 21 / 43 MC/DCmcdc 4.1% 1 / 24 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 65.4% 123 / 188 CC 39 SCAR 29.4
CC
39
Cov
73%
wait_for_completion
28.3
__ANON__
17.8
update_status
15.8
CRAP 18.9
« SDK/Core.pm ↑ Summary SDK/AppConfiguration/Serializer.pm »
1 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4
5 2 class Azure::SDK::AppConfiguration::CreateSnapshotOperation {
6 2 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶ use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 2 field $snapshot :param :reader;
11 2 field $poll_operation :param;
12 2 field $get_snapshot :param;
13 2 field $clock :param = undef;
14 2 field $sleeper :param = undef;
15 2 field $completed :reader = 0;
16
17 3 ▶ ADJUST {
Subroutine __ANON__: called CC=12 SCAR=28.8
18 3 ▶ croak 'CreateSnapshotOperation requires a ConfigurationSnapshot'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($snapshot) and $snapshot->isa("Azure::SDK::AppConfiguration::ConfigurationSnapshot") 0 3 3
Condition33%1/3
builtin::blessed($snapshot) and $snapshot->isa("Azure::SDK::AppConfiguration::ConfigurationSnapshot")
!ll&&!rl&&r
003
MC/DC0%0/2
builtin::blessed($snapshot) and $snapshot->isa("Azure::SDK::AppConfiguration::ConfigurationSnapshot")
builtin::blessed($snapshot) $snapshot->isa("Azure::SDK::AppConfiguration::ConfigurationSnapshot")
Truth table33%1/3
A and B
A= builtin::blessed($snapshot)B= $snapshot->isa("Azure::SDK::AppConfiguration::ConfigurationSnapshot")
ABresult
0X0
100
111
19 unless blessed($snapshot)
20 && $snapshot->isa('Azure::SDK::AppConfiguration::ConfigurationSnapshot');
21 3 ▶ croak 'CreateSnapshotOperation poll_operation must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $poll_operation eq "CODE" 0 3 3
22 unless ref $poll_operation eq 'CODE';
23 3 ▶ croak 'CreateSnapshotOperation get_snapshot must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $get_snapshot eq "CODE" 0 3 3
24 unless ref $get_snapshot eq 'CODE';
25 3 ▶ croak 'CreateSnapshotOperation clock must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $clock and ref $clock ne "CODE" 0 3 3
Condition66%2/3
defined $clock and ref $clock ne "CODE"
!ll&&!rl&&r
210
MC/DC0%0/2
defined $clock and ref $clock ne "CODE"
defined $clock ref $clock ne "CODE"
Truth table66%2/3
A and B
A= defined $clockB= ref $clock ne "CODE"
ABresult
0X0
100
111
26 if defined $clock && ref $clock ne 'CODE';
27 3 ▶ croak 'CreateSnapshotOperation sleeper must be a code reference'
Branch: 1 branch
BranchTrueFalseTotal
if defined $sleeper and ref $sleeper ne "CODE" 0 3 3
Condition66%2/3
defined $sleeper and ref $sleeper ne "CODE"
!ll&&!rl&&r
210
MC/DC0%0/2
defined $sleeper and ref $sleeper ne "CODE"
defined $sleeper ref $sleeper ne "CODE"
Truth table66%2/3
A and B
A= defined $sleeperB= ref $sleeper ne "CODE"
ABresult
0X0
100
111
28 if defined $sleeper && ref $sleeper ne 'CODE';
29 3 ▶ $clock //= sub { Time::HiRes::time() };
Condition66%2/3
$clock //= sub { &Time::HiRes::time(); }
l!l&&r!l&&!r
120
MC/DC0%0/2
$clock //= sub { &Time::HiRes::time(); }
$clock sub { &Time::HiRes::time(); }
Truth table66%2/3
A //= B
A= $clockB= sub { &Time::HiRes::time(); }
ABresult
1X1
011
000
30 3 ▶ $sleeper //= sub ($seconds) { Time::HiRes::sleep($seconds) };
Condition66%2/3
$sleeper //= sub ($seconds) { &Time::HiRes::sleep($seconds); }
l!l&&r!l&&!r
120
MC/DC0%0/2
$sleeper //= sub ($seconds) { &Time::HiRes::sleep($seconds); }
$sleeper sub ($seconds) { &Time::HiRes::sleep($seconds); }
Truth table66%2/3
A //= B
A= $sleeperB= sub ($seconds) { &Time::HiRes::sleep($seconds); }
ABresult
1X1
011
000
31 3 ▶ $completed = 1 if $snapshot->status eq 'ready';
Branch: 1 branch
BranchTrueFalseTotal
if $snapshot->status eq "ready" 0 3 3
32 }
33
34 3 ▶ method update_status () {
Subroutine update_status: called CC=12 SCAR=27.6
Pod documented
35 3 ▶ return $snapshot if $completed;
Branch: 1 branch
BranchTrueFalseTotal
if $completed 0 3 3
36 3 my $result = $poll_operation->();
37 3 ▶ croak 'Snapshot operation poll result must be a hash reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result eq "HASH" 0 3 3
38 unless ref $result eq 'HASH';
39 3 ▶ my $status = $result->{status} // '';
Condition50%1/2
$result->{"status"} // ""
l!l
30
MC/DC0%0/1
$result->{"status"} // ""
$result->{"status"}
Truth table50%1/2
A
A= $result->{"status"}
Aresult
11
00
40 3 ▶ if (lc($status) eq 'succeeded') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $status eq "succeeded") 1 2 3
41 1 $snapshot = $get_snapshot->();
42 1 $completed = 1;
43 1 return $snapshot;
44 }
45 2 ▶ if (lc($status) eq 'failed' || lc($status) eq 'canceled') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $status eq "failed" or lc $status eq "canceled") 1 1 2
Condition66%2/3
lc $status eq "failed" or lc $status eq "canceled"
l!l&&r!l&&!r
101
MC/DC50%1/2
lc $status eq "failed" or lc $status eq "canceled"
lc $status eq "failed" lc $status eq "canceled"
Truth table66%2/3
A or B
A= lc $status eq "failed"B= lc $status eq "canceled"
ABresult
1X1
011
000
46 1 ▶ my $error = ref $result->{error} eq 'HASH' ? $result->{error} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $result->{'error'} eq 'HASH' ? : 1 0 1
47 1 my $canceled = lc($status) eq 'canceled';
48 1 require Azure::SDK::Core::Error;
49 Azure::SDK::Core::Error->new(
50 message => $error->{message} // ($canceled
51 ? 'App Configuration snapshot creation was canceled'
52 : 'App Configuration snapshot creation failed'),
53 1 ▶ code => $error->{code} // ($canceled ? 'Canceled' : undef),
Branch: 2 branches
BranchTrueFalseTotal
$canceled ? : 0 0 0
$canceled ? : 0 0 0
Condition50%2/4
$error->{"message"} // ($canceled ? "App Configuration snapshot creation was canceled" : "App Configuration snapshot creation failed")
l!l
10
$error->{"code"} // ($canceled ? "Canceled" : undef)
l!l
10
MC/DC0%0/1
$error->{"message"} // ($canceled ? "App Configuration snapshot creation was canceled" : "App Configuration snapshot creation failed")
$error->{"message"}
MC/DC0%0/1
$error->{"code"} // ($canceled ? "Canceled" : undef)
$error->{"code"}
Truth table50%1/2
A
A= $error->{"message"}
Aresult
11
00
Truth table50%1/2
A
A= $error->{"code"}
Aresult
11
00
54 )->throw;
55 }
56 1 return $snapshot;
57 }
58
59 2 ▶ method wait_for_completion (%options) {
Subroutine wait_for_completion: called CC=17 SCAR=33.4
Pod documented
60 2 my %allowed = map { $_ => 1 } qw(poll_interval timeout);
61 2 my @unknown = sort grep { !$allowed{$_} } keys %options;
62 2 ▶ croak 'Unknown snapshot wait option(s): ' . join(', ', @unknown)
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 2 2
63 if @unknown;
64 2 ▶ my $poll_interval = $options{poll_interval} // 1;
Condition50%1/2
$options{"poll_interval"} // 1
l!l
20
MC/DC0%0/1
$options{"poll_interval"} // 1
$options{"poll_interval"}
Truth table50%1/2
A
A= $options{"poll_interval"}
Aresult
11
00
65 2 ▶ my $timeout = $options{timeout} // 60;
Condition50%1/2
$options{"timeout"} // 60
l!l
20
MC/DC0%0/1
$options{"timeout"} // 60
$options{"timeout"}
Truth table50%1/2
A
A= $options{"timeout"}
Aresult
11
00
66 2 ▶ croak 'Snapshot poll_interval must be a non-negative number'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $poll_interval and not ref $poll_interval and $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u 0 2 2
Condition33%2/6
defined $poll_interval and not ref $poll_interval and $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
!ll&&!rl&&r
002
defined $poll_interval and not ref $poll_interval
!ll&&!rl&&r
002
MC/DC0%0/3
defined $poll_interval and not ref $poll_interval and $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
defined $poll_interval not ref $poll_interval $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
Truth table25%1/4
A and not(B) and C
A= defined $poll_intervalB= not ref $poll_intervalC= $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
ABCresult
0XX0
10X0
1100
1111
67 unless defined $poll_interval && !ref $poll_interval
68 && $poll_interval =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/;
69 2 ▶ croak 'Snapshot timeout must be a positive number'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $timeout and not ref $timeout and $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $timeout > 0 0 2 2
Condition33%3/9
defined $timeout and not ref $timeout and $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $timeout > 0
!ll&&!rl&&r
002
defined $timeout and not ref $timeout and $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u
!ll&&!rl&&r
002
defined $timeout and not ref $timeout
!ll&&!rl&&r
002
MC/DC0%0/4
defined $timeout and not ref $timeout and $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u and $timeout > 0
defined $timeout not ref $timeout $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/u $timeout > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $timeoutB= not ref $timeoutC= $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/uD= $timeout > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
70 unless defined $timeout && !ref $timeout
71 && $timeout =~ /\A(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)\z/
72 && $timeout > 0;
73
74 2 my $deadline = $clock->() + $timeout;
75 2 ▶ while (!$completed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($completed) 3 0 3
76 3 ▶ croak 'App Configuration snapshot creation timed out'
Branch: 1 branch
BranchTrueFalseTotal
if &$clock() >= $deadline 1 2 3
77 if $clock->() >= $deadline;
78 2 $self->update_status;
79 2 ▶ last if $completed;
Branch: 1 branch
BranchTrueFalseTotal
if $completed 1 1 2
80 1 my $remaining = $deadline - $clock->();
81 1 ▶ croak 'App Configuration snapshot creation timed out'
Branch: 1 branch
BranchTrueFalseTotal
if $remaining <= 0 0 1 1
82 if $remaining <= 0;
83 1 ▶ my $delay = $poll_interval < $remaining
Branch: 1 branch
BranchTrueFalseTotal
$poll_interval < $remaining ? : 0 1 1
84 ? $poll_interval
85 : $remaining;
86 1 ▶ $sleeper->($delay) if $delay > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $delay > 0 1 0 1
87 }
88 1 return $snapshot;
89 }
90 }
91
92 2 1;
93
94 __END__
« SDK/Core.pm ↑ Summary SDK/AppConfiguration/Serializer.pm »