line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::EasyMock::MockControl::Class; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Test::EasyMock::MockControl::Class - Control behavior of the class method mocking. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
1
|
|
|
1
|
|
867
|
use parent qw(Test::EasyMock::MockControl); |
|
1
|
|
|
|
|
344
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
66
|
use Carp qw(confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
12
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
13
|
1
|
|
|
1
|
|
1143
|
use Test::MockModule; |
|
1
|
|
|
|
|
1590
|
|
|
1
|
|
|
|
|
264
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 CONSTRUCTORS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 new($module) |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Create a control instance for class method mocking. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
sub new { |
23
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
24
|
1
|
|
|
|
|
10
|
my $self = $class->SUPER::new(@_); |
25
|
|
|
|
|
|
|
|
26
|
1
|
50
|
|
|
|
14
|
confess('Requires module or object at an argument.(e.g. create_class_mock') |
27
|
|
|
|
|
|
|
unless $self->{_module}; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
5
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 replay |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Change to I mode. |
37
|
|
|
|
|
|
|
Override for creating C and mocking class method. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
sub replay { |
41
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
42
|
5
|
|
|
|
|
25
|
$self->SUPER::replay(@_); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# prevent circular reference |
45
|
5
|
|
|
|
|
9
|
my ($mock) = @_; |
46
|
5
|
|
|
|
|
12
|
weaken($mock); |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
29
|
my $mock_module = Test::MockModule->new($self->{_module}); |
49
|
5
|
|
|
|
|
186
|
foreach my $expectation (@{$self->{_expectations}}) { |
|
5
|
|
|
|
|
14
|
|
50
|
5
|
|
|
|
|
15
|
my $method = $expectation->method; |
51
|
|
|
|
|
|
|
$mock_module->mock($method => sub { |
52
|
2
|
|
|
2
|
|
77
|
my $class = shift; |
53
|
2
|
|
|
|
|
12
|
return $mock->$method(@_); |
54
|
5
|
|
|
|
|
33
|
}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
305
|
$self->{_mock_module} = $mock_module; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 reset |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Clear expectations and change to I mode. |
63
|
|
|
|
|
|
|
Override for release C instance. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
sub reset { |
67
|
5
|
|
|
5
|
1
|
8
|
my $self = shift; |
68
|
5
|
|
|
|
|
25
|
$self->SUPER::reset(@_); |
69
|
5
|
|
|
|
|
57
|
$self->{_mock_module} = undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |