line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::Quick::Object; |
2
|
7
|
|
|
7
|
|
2022
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
235
|
|
3
|
7
|
|
|
7
|
|
37
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
174
|
|
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
2698
|
use Mock::Quick::Util; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
574
|
|
6
|
7
|
|
|
7
|
|
4142
|
use Mock::Quick::Object::Control; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
327
|
|
7
|
7
|
|
|
7
|
|
47
|
use Carp (); |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
241
|
|
8
|
7
|
|
|
7
|
|
42
|
use Scalar::Util (); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
2563
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $AUTOLOAD; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
class_meth new => sub { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
my %proto = @_; |
15
|
|
|
|
|
|
|
return bless \%proto, $class; |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub AUTOLOAD { |
19
|
|
|
|
|
|
|
# Do not shift this, we need it when we use goto &$sub |
20
|
8
|
|
|
8
|
|
1621
|
my ($self) = @_; |
21
|
8
|
|
|
|
|
59
|
my ( $package, $sub ) = ( $AUTOLOAD =~ m/^(.+)::([^:]+)$/ ); |
22
|
8
|
|
|
|
|
19
|
$AUTOLOAD = undef; |
23
|
|
|
|
|
|
|
|
24
|
8
|
50
|
|
|
|
46
|
Carp::croak "Can't locate object method \"$sub\" via package \"$package\"" |
25
|
|
|
|
|
|
|
unless Scalar::Util::blessed( $self ); |
26
|
|
|
|
|
|
|
|
27
|
8
|
|
|
|
|
39
|
my $code = $self->can( $sub ); |
28
|
8
|
100
|
|
|
|
47
|
Carp::croak "Can't locate object method \"$sub\" in this instance" |
29
|
|
|
|
|
|
|
unless $code; |
30
|
|
|
|
|
|
|
|
31
|
7
|
|
|
|
|
24
|
goto &$code; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
alt_meth can => ( |
35
|
7
|
|
|
7
|
|
59
|
class => sub { no warnings 'misc'; goto &UNIVERSAL::can }, |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
812
|
|
36
|
|
|
|
|
|
|
obj => sub { |
37
|
|
|
|
|
|
|
my ( $self, $name ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $control = Mock::Quick::Object::Control->new( $self ); |
40
|
|
|
|
|
|
|
return if $control->strict && !exists $self->{$name}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $sub; |
43
|
|
|
|
|
|
|
{ |
44
|
7
|
|
|
7
|
|
36
|
no warnings 'misc'; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
1231
|
|
45
|
|
|
|
|
|
|
$sub = UNIVERSAL::can( $self, $name ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
$sub ||= sub { |
48
|
43
|
|
|
43
|
|
1867
|
unshift @_ => ( shift( @_ ), $name ); |
49
|
43
|
|
|
|
|
194
|
goto &call; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
inject( Scalar::Util::blessed( $self ), $name, $sub ); |
52
|
|
|
|
|
|
|
return $sub; |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# http://perldoc.perl.org/perlobj.html#Default-UNIVERSAL-methods |
57
|
|
|
|
|
|
|
# DOES is equivalent to isa by default |
58
|
7
|
|
|
7
|
0
|
44
|
sub isa { no warnings 'misc'; goto &UNIVERSAL::isa } |
|
7
|
|
|
8
|
|
62
|
|
|
7
|
|
|
|
|
701
|
|
|
8
|
|
|
|
|
5691
|
|
59
|
0
|
|
|
0
|
0
|
|
sub DOES { goto &isa } |
60
|
7
|
|
|
7
|
0
|
38
|
sub VERSION { no warnings 'misc'; goto &UNIVERSAL::VERSION } |
|
7
|
|
|
0
|
|
11
|
|
|
7
|
|
|
|
|
970
|
|
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
obj_meth DESTROY => sub { |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
Mock::Quick::Object::Control->new( $self )->_clean; |
65
|
|
|
|
|
|
|
unshift @_ => ( $self, 'DESTROY' ); |
66
|
|
|
|
|
|
|
goto &call; |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
purge_util(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Mock::Quick::Object - Object mocking for Mock::Quick |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Provides object mocking. See L<Mock::Quick> for a better interface. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use Mock::Quick::Object; |
86
|
|
|
|
|
|
|
use Mock::Quick::Method; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $obj = Mock::Quick::Object->new( |
89
|
|
|
|
|
|
|
foo => 'bar', # define attribute |
90
|
|
|
|
|
|
|
do_it => qmeth { ... }, # define method |
91
|
|
|
|
|
|
|
... |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
is( $obj->foo, 'bar' ); |
95
|
|
|
|
|
|
|
$obj->foo( 'baz' ); |
96
|
|
|
|
|
|
|
is( $obj->foo, 'baz' ); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$obj->do_it(); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# define the new attribute automatically |
101
|
|
|
|
|
|
|
$obj->bar( 'xxx' ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# define a new method on the fly |
104
|
|
|
|
|
|
|
$obj->baz( Mock::Quick::Method->new( sub { ... }); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# remove an attribute or method |
107
|
|
|
|
|
|
|
$obj->baz( \$Mock::Quick::Util::CLEAR ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHORS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Chad Granum L<exodist7@gmail.com> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Copyright (C) 2011 Chad Granum |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Mock-Quick is free software; Standard perl licence. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Mock-Quick is distributed in the hope that it will be useful, but WITHOUT ANY |
120
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
121
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the license for more details. |