| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBD::Mock::Session; |
|
2
|
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
293
|
use strict; |
|
|
40
|
|
|
|
|
83
|
|
|
|
40
|
|
|
|
|
1253
|
|
|
4
|
40
|
|
|
40
|
|
206
|
use warnings; |
|
|
40
|
|
|
|
|
73
|
|
|
|
40
|
|
|
|
|
44710
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $INSTANCE_COUNT = 1; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# - Class - # |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
35
|
|
|
35
|
0
|
13498
|
my $class = shift; |
|
12
|
35
|
100
|
|
|
|
160
|
my $name = ref( $_[0] ) ? "Session $INSTANCE_COUNT" : shift; |
|
13
|
35
|
|
|
|
|
169
|
$INSTANCE_COUNT++; |
|
14
|
|
|
|
|
|
|
|
|
15
|
35
|
|
|
|
|
163
|
$class->_verify_states( $name, @_ ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
26
|
|
|
|
|
190
|
bless { |
|
18
|
|
|
|
|
|
|
name => $name, |
|
19
|
|
|
|
|
|
|
states => \@_, |
|
20
|
|
|
|
|
|
|
state_index => 0 |
|
21
|
|
|
|
|
|
|
}, $class; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _verify_state { |
|
25
|
55
|
|
|
55
|
|
125
|
my ( $class, $state, $index, $name ) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
55
|
100
|
|
|
|
156
|
die "You must specify session states as HASH refs" |
|
28
|
|
|
|
|
|
|
if ref($state) ne 'HASH'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
die "Bad state '$index' in DBD::Mock::Session ($name)" |
|
31
|
|
|
|
|
|
|
if not exists $state->{statement} |
|
32
|
52
|
100
|
100
|
|
|
273
|
or not exists $state->{results}; |
|
33
|
|
|
|
|
|
|
|
|
34
|
49
|
|
|
|
|
87
|
my $stmt = $state->{statement}; |
|
35
|
49
|
|
|
|
|
88
|
my $ref = ref $stmt; |
|
36
|
|
|
|
|
|
|
|
|
37
|
49
|
100
|
100
|
|
|
213
|
die "Bad 'statement' value '$stmt' in DBD::Mock::Session ($name)", |
|
|
|
|
100
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ref($stmt) ne '' |
|
39
|
|
|
|
|
|
|
and $ref ne 'CODE' |
|
40
|
|
|
|
|
|
|
and $ref ne 'Regexp'; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _verify_states { |
|
44
|
35
|
|
|
35
|
|
92
|
my ( $class, $name, @states ) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
35
|
100
|
|
|
|
136
|
die "You must specify at least one session state" |
|
47
|
|
|
|
|
|
|
if scalar @states == 0; |
|
48
|
|
|
|
|
|
|
|
|
49
|
33
|
|
|
|
|
134
|
for ( 0 .. scalar @states - 1 ) { |
|
50
|
55
|
|
|
|
|
137
|
$class->_verify_state( $states[$_], $_, $name ); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# - Instance - # |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub name { |
|
57
|
6
|
|
|
6
|
0
|
2321
|
my $self = shift; |
|
58
|
6
|
|
|
|
|
26
|
$self->{name}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub reset { |
|
62
|
1
|
|
|
1
|
0
|
953
|
my $self = shift; |
|
63
|
1
|
|
|
|
|
4
|
$self->{state_index} = 0; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub current_state { |
|
67
|
138
|
|
|
138
|
0
|
219
|
my $self = shift; |
|
68
|
138
|
|
|
|
|
201
|
my $idx = $self->{state_index}; |
|
69
|
138
|
|
|
|
|
260
|
return $self->{states}[$idx]; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub has_states_left { |
|
73
|
66
|
|
|
66
|
0
|
113
|
my $self = shift; |
|
74
|
66
|
|
|
|
|
144
|
return $self->{state_index} < $self->_num_states; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub verify_statement { |
|
78
|
52
|
|
|
52
|
0
|
133
|
my ( $self, $got ) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
52
|
100
|
|
|
|
131
|
unless ( $self->has_states_left ) { |
|
81
|
6
|
|
|
|
|
14
|
die "Session states exhausted, only '" |
|
82
|
|
|
|
|
|
|
. $self->_num_states |
|
83
|
|
|
|
|
|
|
. "' in DBD::Mock::Session ($self->name})"; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
46
|
|
|
|
|
106
|
my $state = $self->current_state; |
|
87
|
46
|
|
|
|
|
87
|
my $expected = $state->{statement}; |
|
88
|
46
|
|
|
|
|
84
|
my $ref = ref($expected); |
|
89
|
|
|
|
|
|
|
|
|
90
|
46
|
100
|
100
|
|
|
225
|
if ( $ref eq 'Regexp' and $got !~ /$expected/ ) { |
|
91
|
1
|
|
|
|
|
14
|
die "Statement does not match current state (with Regexp) in " |
|
92
|
|
|
|
|
|
|
. "DBD::Mock::Session ($self->{name})\n" |
|
93
|
|
|
|
|
|
|
. " got: $got\n" |
|
94
|
|
|
|
|
|
|
. " expected: $expected", |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
45
|
100
|
100
|
|
|
236
|
if ( $ref eq 'CODE' and not $expected->( $got, $state ) ) { |
|
99
|
1
|
|
|
|
|
13
|
die "Statement does not match current state (with CODE ref) in " |
|
100
|
|
|
|
|
|
|
. "DBD::Mock::Session ($self->{name})"; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
44
|
100
|
100
|
|
|
259
|
if ( not $ref and $got ne $expected ) { |
|
104
|
1
|
|
|
|
|
14
|
die "Statement does not match current state in " |
|
105
|
|
|
|
|
|
|
. "DBD::Mock::Session ($self->{name})\n" |
|
106
|
|
|
|
|
|
|
. " got: $got\n" |
|
107
|
|
|
|
|
|
|
. " expected: $expected"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub results_for { |
|
112
|
46
|
|
|
46
|
0
|
125
|
my ( $self, $statment ) = @_; |
|
113
|
46
|
|
|
|
|
147
|
$self->_find_state_for($statment)->{results}; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub verify_bound_params { |
|
117
|
43
|
|
|
43
|
0
|
97
|
my ( $self, $params ) = @_; |
|
118
|
|
|
|
|
|
|
|
|
119
|
43
|
|
|
|
|
123
|
my $current_state = $self->current_state; |
|
120
|
43
|
100
|
|
|
|
63
|
if ( exists ${$current_state}{bound_params} ) { |
|
|
43
|
|
|
|
|
130
|
|
|
121
|
21
|
|
|
|
|
46
|
my $expected = $current_state->{bound_params}; |
|
122
|
|
|
|
|
|
|
|
|
123
|
21
|
100
|
|
|
|
74
|
if ( scalar @$expected != scalar @$params ) { |
|
124
|
1
|
|
|
|
|
6
|
die "Not the same number of bound params in current state in " |
|
125
|
|
|
|
|
|
|
. "DBD::Mock::Session ($self->{name})\n" |
|
126
|
1
|
|
|
|
|
6
|
. " got: @{$params}" |
|
127
|
1
|
|
|
|
|
13
|
. " expected: @{$expected}"; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
20
|
|
|
|
|
33
|
for ( 0 .. scalar @{$params} - 1 ) { |
|
|
20
|
|
|
|
|
87
|
|
|
131
|
26
|
|
|
|
|
94
|
$self->_verify_bound_param( $params->[$_], $expected->[$_], $_ ); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# and make sure we go to |
|
137
|
|
|
|
|
|
|
# the next statement |
|
138
|
40
|
|
|
|
|
103
|
$self->{state_index}++; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub _find_state_for { |
|
142
|
46
|
|
|
46
|
|
96
|
my ( $self, $statement ) = @_; |
|
143
|
|
|
|
|
|
|
|
|
144
|
46
|
|
|
|
|
141
|
foreach ( $self->_remaining_states ) { |
|
145
|
42
|
|
|
|
|
86
|
my $stmt = $_->{statement}; |
|
146
|
42
|
|
|
|
|
81
|
my $ref = ref($stmt); |
|
147
|
|
|
|
|
|
|
|
|
148
|
42
|
100
|
100
|
|
|
216
|
return $_ if ( $ref eq 'Regexp' and $statement =~ /$stmt/ ); |
|
149
|
35
|
100
|
66
|
|
|
122
|
return $_ if ( $ref eq 'CODE' and $stmt->( $statement, $_ ) ); |
|
150
|
31
|
100
|
66
|
|
|
233
|
return $_ if ( not $ref and $stmt eq $statement ); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
5
|
|
|
|
|
47
|
die "Statement '$statement' not found in session ($self->{name})"; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _num_states { |
|
157
|
118
|
|
|
118
|
|
177
|
my $self = shift; |
|
158
|
118
|
|
|
|
|
157
|
scalar @{ $self->{states} }; |
|
|
118
|
|
|
|
|
1698
|
|
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _remaining_states { |
|
162
|
46
|
|
|
46
|
|
84
|
my $self = shift; |
|
163
|
46
|
|
|
|
|
88
|
my $start_index = $self->{state_index}; |
|
164
|
46
|
|
|
|
|
117
|
my $end_index = $self->_num_states - 1; |
|
165
|
46
|
|
|
|
|
112
|
@{ $self->{states} }[ $start_index .. $end_index ]; |
|
|
46
|
|
|
|
|
166
|
|
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _verify_bound_param { |
|
169
|
26
|
|
|
26
|
|
80
|
my ( $self, $got, $expected, $index ) = @_; |
|
170
|
40
|
|
|
40
|
|
374
|
no warnings; |
|
|
40
|
|
|
|
|
91
|
|
|
|
40
|
|
|
|
|
8199
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
26
|
|
|
|
|
46
|
my $ref = ref $expected; |
|
173
|
|
|
|
|
|
|
|
|
174
|
26
|
100
|
|
|
|
117
|
if ( $ref eq 'Regexp' ) { |
|
|
|
100
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
1
|
50
|
|
|
|
10
|
if ( $got !~ /$expected/ ) { |
|
177
|
0
|
|
|
|
|
0
|
die "Bound param $index do not match (using regexp) " |
|
178
|
|
|
|
|
|
|
. "in current state in DBD::Mock::Session ($self->{name})" |
|
179
|
|
|
|
|
|
|
. " got: $got\n" |
|
180
|
|
|
|
|
|
|
. " expected: $expected"; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} elsif ( $got ne $expected ) { |
|
184
|
2
|
|
|
|
|
39
|
die "Bound param $index do not match " |
|
185
|
|
|
|
|
|
|
. "in current state in DBD::Mock::Session ($self->{name})\n" |
|
186
|
|
|
|
|
|
|
. " got: $got\n" |
|
187
|
|
|
|
|
|
|
. " expected: $expected"; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |