forked from ePages-de/Mockify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MethodCallCounter.pm
94 lines (85 loc) · 3.94 KB
/
MethodCallCounter.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#========================================================================================
# §package MethodCallCounter
# §state public
#----------------------------------------------------------------------------------------
# §description encapsulate the Call Counter for Mockify
#========================================================================================
package MethodCallCounter;
use Tools qw ( Error );
use strict;
#========================================================================================
# §function new
# §state public
#----------------------------------------------------------------------------------------
# §syntax new( );
#----------------------------------------------------------------------------------------
# §description constructor
#----------------------------------------------------------------------------------------
# §return $self | self | MethodCallCounter
#========================================================================================
sub new {
my $class = shift;
my $self = bless {}, $class;
return $self;
}
#========================================================================================
# §function addMethod
# §state public
#----------------------------------------------------------------------------------------
# §syntax addMethod( $MethodName );
#----------------------------------------------------------------------------------------
# §description add the Method '$MethodName' to the counter
#----------------------------------------------------------------------------------------
# §input $MethodName | name of method | string
#========================================================================================
sub addMethod {
my $self = shift;
my ( $MethodName ) = @_;
$self->{$MethodName} = 0;
return;
}
#========================================================================================
# §function increment
# §state public
#----------------------------------------------------------------------------------------
# §syntax increment( $MethodName );
#----------------------------------------------------------------------------------------
# §description increment the the counter for the Method '$MethodName'
#----------------------------------------------------------------------------------------
# §input $MethodName | name of method | string
#========================================================================================
sub increment {
my $self = shift;
my ( $MethodName ) = @_;
$self->_testIfMethodWasAdded( $MethodName );
$self->{$MethodName} += 1;
return;
}
#========================================================================================
# §function getAmountOfCalls
# §state public
#----------------------------------------------------------------------------------------
# §syntax getAmountOfCalls( $MethodName );
#----------------------------------------------------------------------------------------
# §description returns the amount of calls for the method '$MethodName'
# throws error if the method was not added to Mockify
#----------------------------------------------------------------------------------------
# §input $MethodName | name of method | string
# §return $AmountOfCalls | Amount of calles | integer
#========================================================================================
sub getAmountOfCalls {
my $self = shift;
my ( $MethodName ) = @_;
$self->_testIfMethodWasAdded( $MethodName );
my $AmountOfCalls = $self->{ $MethodName };
return $AmountOfCalls;
}
#----------------------------------------------------------------------------------------
sub _testIfMethodWasAdded {
my $self = shift;
my ( $MethodName ) = @_;
if( not exists $self->{ $MethodName } ){
Error( "The Method: '$MethodName' was not added to Mockify" );
}
}
1;