File Coverage

blib/lib/App/PerlWatcher/Shelf.pm
Criterion Covered Total %
statement 34 34 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 9 9 100.0
pod 2 2 100.0
total 50 52 96.1


line stmt bran cond sub pod time code
1             package App::PerlWatcher::Shelf;
2             {
3             $App::PerlWatcher::Shelf::VERSION = '0.20';
4             }
5             # ABSTRACT: Used to stash (store) statuses for further detection weather they has been changed.
6              
7 5     5   854 use 5.12.0;
  5         19  
  5         221  
8 5     5   45 use strict;
  5         10  
  5         159  
9 5     5   28 use warnings;
  5         9  
  5         166  
10              
11 5     5   28 use Smart::Comments -ENV;
  5         8  
  5         59  
12 5     5   1567 use Moo;
  5         11  
  5         40  
13 5     5   6159 use Scalar::Util qw/refaddr/;
  5         13  
  5         281  
14 5     5   2580 use Storable;
  5         9035  
  5         1520  
15              
16             has 'statuses' => ( is => 'rw', default => sub { {}; } );
17              
18              
19             sub stash_status {
20 9     9 1 68 my ($self, $status) = @_;
21 9         16 my $same_as_previous = 0;
22 9 50       60 if ( defined($status) ) {
23 9         233 my $previous = $self->statuses->{ $status -> watcher };
24 9   66     187 $same_as_previous = $previous && (refaddr($previous) == refaddr($status));
25 9         56 $self->statuses->{ $status -> watcher } = $status;
26             }
27 9         346 return $same_as_previous;
28             }
29              
30              
31             sub status_changed {
32 18     18 1 9933 my ($self, $status) = @_;
33 18         65 my $watcher = $status -> watcher;
34 18         106 my $stashed_status = $self->statuses->{$watcher};
35 18 100       674 return 1 unless $stashed_status;
36 13         70 my $updated = $stashed_status->updated_from($status);
37             # $updated
38 13         65 return $updated;
39             }
40              
41             1;
42              
43             __END__