File Coverage

blib/lib/App/PerlWatcher/UI/Gtk2/URLOpener.pm
Criterion Covered Total %
statement 18 27 66.6
branch n/a
condition n/a
subroutine 6 8 75.0
pod 1 1 100.0
total 25 36 69.4


line stmt bran cond sub pod time code
1             package App::PerlWatcher::UI::Gtk2::URLOpener;
2             {
3             $App::PerlWatcher::UI::Gtk2::URLOpener::VERSION = '0.09';
4             }
5             # ABSTRACT: The class is responsible for opening urls after a shord idle.
6              
7 1     1   34497 use 5.12.0;
  1         3  
  1         47  
8 1     1   4 use strict;
  1         2  
  1         25  
9 1     1   6 use warnings;
  1         1  
  1         34  
10              
11 1     1   4 use AnyEvent;
  1         3  
  1         25  
12 1     1   1128 use Moo;
  1         19053  
  1         7  
13 1     1   2376 use Scalar::Util qw/weaken/;
  1         2  
  1         365  
14              
15              
16              
17             has 'openables' => ( is => 'rw', default => sub{ []; } );
18              
19              
20             has 'timer' => (is => 'rw');
21              
22              
23             has 'delay' => (is => 'rw', required => 1);
24              
25              
26             has 'callback' => (is => 'rw', required => 1);
27              
28              
29             sub delayed_open {
30 0     0 1   my ($self, $openable) = @_;
31 0           push @{ $self->openables }, $openable;
  0            
32              
33 0           weaken $self;
34             $self->timer(
35             AnyEvent->timer(
36             after => $self->delay,
37             cb => sub {
38 0     0     my $openables = $self->openables;
39 0           $_->open_url for( @$openables );
40 0           $self->openables([]);
41 0           $self->callback->($openables);
42             }
43             )
44 0           );
45             }
46              
47             1;
48              
49             __END__