Selenium/Waiter.pm

filter: Statementstmt 100% 36 / 36 Branchbran 93.7% 15 / 16 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 95.4% 63 / 66 CC 10 SCAR 12.1
CC
10
Cov
96%
wait_until
6.0
__ANON__
3.0
__ANON__
2.0
CRAP 3.4
« Test/Selenium/Remote/Role/DoesTesting.pm ↑ Summary Selenium/CanStartBinary/ProbePort.pm »
1 package Selenium::Waiter;
2 14 $Selenium::Waiter::VERSION = '1.50';
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Provides a utility wait_until function
7 14 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 require Exporter;
9 14 our @ISA = qw/Exporter/;
10 14 our @EXPORT = qw/wait_until/;
11  
12  
13 8 ▶sub wait_until (&%) {
Subroutine wait_until: called CC=6 SCAR=17.9
Pod documented
14 8 my $assert = shift;
15 8 my $args = {
16 timeout => 30,
17 interval => 1,
18 debug => 0,
19 die => 0,
20 @_
21 };
22  
23 8 my $start = time;
24 11 ▶ my $timeout_not_elapsed = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 11 my $elapsed = time - $start;
26 11 return $elapsed < $args->{timeout};
27 8 };
28  
29 8 my $exception = '';
30 8 ▶ while ( $timeout_not_elapsed->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$timeout_not_elapsed()) 8 3 11
31 8 my $assert_ret;
32 8 ▶ my $try_ret = try {
Subroutine __ANON__: called CC=2 SCAR=6.9
33 8 $assert_ret = $assert->();
34 6 ▶ return $assert_ret if $assert_ret;
Branch: 1 branch
BranchTrueFalseTotal
if $assert_ret 4 2 6
35 }
36 2 ▶ catch {
Subroutine __ANON__: called CC=3 SCAR=11.0
37 2 $exception = $_;
38 2 ▶ die $_ if $args->{die};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"die"} 1 1 2
39 1 ▶ warn $_ if $args->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"debug"} 0 1 1
40 1 return '';
41 }
42 8 ▶ finally {
Subroutine __ANON__: called CC=2 SCAR=6.9
43 8 ▶ if ( !$assert_ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $assert_ret) 4 4 8
44 4 sleep( $args->{interval} );
45 }
46 8 };
47  
48 7 ▶ return $try_ret if $try_ret;
Branch: 1 branch
BranchTrueFalseTotal
if $try_ret 4 3 7
49 }
50  
51 3 ▶ warn 'timeout' if $args->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"debug"} 1 2 3
52  
53 # No need to repeat ourselves if we're already debugging.
54 3 ▶ warn $exception if $exception && !$args->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $exception and not $args->{"debug"} 1 2 3
Condition66%2/3
$exception and not $args->{"debug"}
!ll&&!rl&&r
201
MC/DC50%1/2
$exception and not $args->{"debug"}
$exception not $args->{"debug"}
Truth table66%2/3
A and not(B)
A= $exceptionB= not $args->{"debug"}
ABresult
0X0
100
111
55 3 return '';
56 }
57  
58 14 1;
59  
60 __END__
« Test/Selenium/Remote/Role/DoesTesting.pm ↑ Summary Selenium/CanStartBinary/ProbePort.pm »