| 1 | |||||||||||||
| 2 | package Dancer2::Plugin::ProgressStatus::Object; | ||||||||||||
| 3 | 3 | $Dancer2::Plugin::ProgressStatus::Object::VERSION = '0.018'; | |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | ▶ | use Scalar::Util qw/looks_like_number/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | use overload | ||||||||||||
| 11 | 5 | ▶ | '++' => sub { my ($self, $i) = @_; $self->increment($i) }, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.5
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 0 | ▶ | '--' => sub { my ($self, $i) = @_; $self->decrement($i) }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 13 | 0 | ▶ | '=' => sub { $_[0] }; # should never clone this object | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||
| 14 | |||||||||||||
| 15 | has total => ( | ||||||||||||
| 16 | is => 'ro', | ||||||||||||
| 17 | 4 | ▶ | isa => sub { die 'total must be a number' unless looks_like_number($_[0]) }, | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||
| 18 | 2 | ▶ | default => sub { 100 } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 3 | ); | |||||||||||
| 20 | has count => ( | ||||||||||||
| 21 | is => 'rw', | ||||||||||||
| 22 | 9 | ▶ | isa => sub { die 'count must be a number' unless looks_like_number($_[0]) }, | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||
| 23 | 4 | ▶ | default => sub { 0 } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 3 | ); | |||||||||||
| 25 | has messages => ( | ||||||||||||
| 26 | is => 'ro', | ||||||||||||
| 27 | 4 | ▶ | default => sub { [] }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 3 | ); | |||||||||||
| 29 | has status => ( | ||||||||||||
| 30 | is => 'rw', | ||||||||||||
| 31 | 4 | ▶ | default => sub { 'in progress' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 3 | ); | |||||||||||
| 33 | |||||||||||||
| 34 | has _on_save => ( | ||||||||||||
| 35 | is => 'ro', | ||||||||||||
| 36 | required => 1, | ||||||||||||
| 37 | 4 | ▶ | isa => sub { die 'needs _on_save coderef' unless ref($_[0]) eq 'CODE' }, | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||
| 38 | 3 | ); | |||||||||||
| 39 | |||||||||||||
| 40 | has start_time => ( | ||||||||||||
| 41 | is => 'rw', | ||||||||||||
| 42 | 4 | ▶ | default => sub { time(); } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | 3 | ); | |||||||||||
| 44 | |||||||||||||
| 45 | has current_time => ( | ||||||||||||
| 46 | is => 'rw', | ||||||||||||
| 47 | 4 | ▶ | default => sub { time(); } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 3 | ); | |||||||||||
| 49 | |||||||||||||
| 50 | 50 | ▶ | after [qw/status count/] => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 51 | 50 | ▶ | if ( $_[1] ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 5 | $_[0]->save(); | |||||||||||
| 53 | } | ||||||||||||
| 54 | 3 | }; | |||||||||||
| 55 | |||||||||||||
| 56 | 4 | ▶ | sub finish { | ||||||||||
|
Subroutine
finish: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 57 | 4 | my ( $self ) = @_; | |||||||||||
| 58 | |||||||||||||
| 59 | 4 | $self->save(1); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 20 | ▶ | sub save { | ||||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 63 | 20 | my ( $self, $is_finished ) = @_; | |||||||||||
| 64 | 20 | $self->current_time(time()); | |||||||||||
| 65 | 20 | $self->_on_save->($self, $is_finished); | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 5 | ▶ | sub increment { | ||||||||||
|
Subroutine
increment: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||
| 69 | 5 | my ( $self, $increment, @messages ) = @_; | |||||||||||
| 70 | |||||||||||||
| 71 | 5 | ▶ | $increment ||= 1; | ||||||||||
|
Condition50%1/2
$increment ||= 1
MC/DC0%0/1
$increment ||= 1
$increment
Truth table50%1/2
A
A= $increment
| |||||||||||||
| 72 | 5 | $self->count($self->count + $increment); | |||||||||||
| 73 | 5 | ▶ | if ( @messages ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 0 | push @{$self->messages}, @messages; | |||||||||||
| 75 | } | ||||||||||||
| 76 | 5 | $self->save(); | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 0 | ▶ | sub decrement { | ||||||||||
|
Subroutine
decrement: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 80 | 0 | my ( $self, $increment, @messages ) = @_; | |||||||||||
| 81 | 0 | ▶ | $increment ||= 1; | ||||||||||
|
Condition0%0/2
$increment ||= 1
MC/DC0%0/1
$increment ||= 1
$increment
Truth table0%0/2
A
A= $increment
| |||||||||||||
| 82 | 0 | $self->count($self->count - $increment); | |||||||||||
| 83 | 0 | ▶ | if ( @messages ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 84 | 0 | push @{$self->messages}, @messages; | |||||||||||
| 85 | } | ||||||||||||
| 86 | 0 | $self->save(); | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 2 | ▶ | sub add_message { | ||||||||||
|
Subroutine
add_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 90 | 2 | my ( $self, @messages ) = @_; | |||||||||||
| 91 | |||||||||||||
| 92 | 2 | push @{$self->messages}, @messages; | |||||||||||
| 93 | 2 | $self->save(); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 4 | ▶ | sub DESTROY { | ||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||
| 97 | 4 | $_[0]->finish(); | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | 3 | ▶ | no Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 3 | 1; | |||||||||||
| 104 | |||||||||||||
| 105 | __END__ | ||||||||||||