File Coverage

blib/lib/Test/Mockify/MethodCallCounter.pm
Criterion Covered Total %
statement 30 30 100.0
branch 2 2 100.0
condition n/a
subroutine 8 8 100.0
pod 0 4 0.0
total 40 44 90.9


line stmt bran cond sub pod time code
1             package Test::Mockify::MethodCallCounter;
2 4     4   14 use Test::Mockify::Tools qw ( Error );
  4         776  
  4         151  
3 4     4   15 use strict;
  4         3  
  4         55  
4 4     4   10 use warnings;
  4         2  
  4         799  
5              
6             sub new {
7 59     59 0 78     my $class = shift;
8 59         101     my $self = bless {}, $class;
9 59         118     return $self;
10             }
11              
12             sub addMethod {
13 66     66 0 54     my $self = shift;
14 66         61     my ( $MethodName ) = @_;
15              
16 66         87     $self->{$MethodName} = 0;
17              
18 66         90     return;
19             }
20              
21             sub increment {
22 74     74 0 64     my $self = shift;
23 74         67     my ( $MethodName ) = @_;
24              
25 74         109     $self->_testIfMethodWasAdded( $MethodName );
26 74         70     $self->{$MethodName} += 1;
27              
28 74         89     return;
29             }
30              
31             sub getAmountOfCalls {
32 15     15 0 18     my $self = shift;
33 15         15     my ( $MethodName ) = @_;
34              
35 15         26     $self->_testIfMethodWasAdded( $MethodName );
36 14         14     my $AmountOfCalls = $self->{ $MethodName };
37              
38 14         28     return $AmountOfCalls;
39             }
40              
41             sub _testIfMethodWasAdded {
42 89     89   63     my $self = shift;
43 89         66     my ( $MethodName ) = @_;
44              
45 89 100       181     if( not exists $self->{ $MethodName } ){
46 1         5         Error( "The Method: '$MethodName' was not added to Mockify" );
47                 }
48             }
49             1;