| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 2 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 37 | 2 | $exception = $_; | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | die $_ if $args->{die}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | warn $_ if $args->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | return ''; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 8 | ▶ | finally { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 8 | ▶ | if ( !$assert_ret ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 4 | sleep( $args->{interval} ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 8 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 7 | ▶ | return $try_ret if $try_ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | warn 'timeout' if $args->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # No need to repeat ourselves if we're already debugging. | ||||||||||||||||||||||||||||
| 54 | 3 | ▶ | warn $exception if $exception && !$args->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$exception and not $args->{"debug"}
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"}
| |||||||||||||||||||||||||||||
| 55 | 3 | return ''; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 14 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||