line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::Data::GeneratorSub; |
2
|
9
|
|
|
9
|
|
68
|
use strict; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
315
|
|
3
|
9
|
|
|
9
|
|
52
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
4492
|
|
4
|
|
|
|
|
|
|
require Mock::Data::Generator; |
5
|
|
|
|
|
|
|
our @ISA= qw( Mock::Data::Generator ); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Wrap a coderef to become a blessed Generator object |
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
13
|
|
|
13
|
1
|
31
|
my ($class, $coderef, @params)= @_; |
13
|
13
|
50
|
|
|
|
36
|
if (ref $coderef eq 'HASH') { |
14
|
0
|
0
|
|
|
|
0
|
@params= @{ $coderef->{params} || [] }; |
|
0
|
|
|
|
|
0
|
|
15
|
0
|
|
|
|
|
0
|
$coderef= $coderef->{coderef}; |
16
|
|
|
|
|
|
|
} |
17
|
13
|
50
|
|
|
|
48
|
if (ref $class) { |
18
|
0
|
|
0
|
|
|
0
|
$coderef ||= $class->{coderef}; |
19
|
0
|
|
|
|
|
0
|
@params= $class->_merge_params(@params); |
20
|
0
|
|
|
|
|
0
|
$class= ref $class; |
21
|
|
|
|
|
|
|
} |
22
|
13
|
50
|
|
|
|
48
|
Scalar::Util::reftype($coderef) eq 'CODE' or Carp::croak("Not a coderef"); |
23
|
13
|
|
|
|
|
82
|
bless { |
24
|
|
|
|
|
|
|
coderef => $coderef, |
25
|
|
|
|
|
|
|
params => \@params, |
26
|
|
|
|
|
|
|
}, $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _merge_params { |
30
|
10
|
|
|
10
|
|
15
|
my $self= shift; |
31
|
10
|
|
|
|
|
29
|
my $p= $self->{params}; |
32
|
10
|
50
|
|
|
|
27
|
my $named_p= ref $p->[0] eq 'HASH'? $p->[0] : undef; |
33
|
|
|
|
|
|
|
# Merge any options-by-name newly supplied with options-by-name from @params |
34
|
10
|
0
|
|
|
|
23
|
unshift @_, (ref $_[0] eq 'HASH')? { %$named_p, %{shift @_} } : $named_p |
|
0
|
50
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
if $named_p; |
36
|
|
|
|
|
|
|
# Append positional params if none provided |
37
|
10
|
100
|
|
|
|
31
|
push @_, @{$p}[1..$#$p] |
|
9
|
|
|
|
|
15
|
|
38
|
|
|
|
|
|
|
unless @_ > 1; |
39
|
10
|
|
|
|
|
34
|
return @_; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub generate { |
44
|
11
|
|
|
11
|
1
|
29
|
my ($self, $mock)= (shift, shift); |
45
|
11
|
100
|
|
|
|
35
|
$self->{coderef}->($mock, @_? $self->_merge_params(@_) : @{$self->{params}}); |
|
1
|
|
|
|
|
20
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub compile { |
50
|
4
|
|
|
4
|
1
|
8
|
my $self= shift; |
51
|
4
|
|
|
|
|
13
|
my $params= $self->{params}; |
52
|
4
|
50
|
33
|
|
|
50
|
return $self->{coderef} unless @_ || @$params; |
53
|
0
|
|
|
|
|
|
my @new_params= $self->_merge_params(@_); |
54
|
0
|
|
|
|
|
|
my $coderef= $self->{coderef}; |
55
|
0
|
|
|
0
|
|
|
return sub { $coderef->(shift, @new_params) }; |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |