Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Test::MockObject::Extends.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "Test::MockObject::Extends 3"
132 .TH Test::MockObject::Extends 3 "2008-05-27" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Test::MockObject::Extends \- mock part of an object or class
135 .SH "SYNOPSIS"
136 .IX Header "SYNOPSIS"
137 .Vb 2
138 \&  use Some::Class;
139 \&  use Test::MockObject::Extends;
140 .Ve
141 .PP
142 .Vb 2
143 \&  # create an object to mock
144 \&  my $object      = Some::Class\->new();
145 .Ve
146 .PP
147 .Vb 2
148 \&  # wrap that same object with a mocking wrapper
149 \&  $object         = Test::MockObject::Extends\->new( $object );
150 .Ve
151 .PP
152 .Vb 4
153 \&  # now chain mock and control calls
154 \&  $object\->set_true( 'parent_method' )
155 \&         \->set_always( \-grandparent_method => 1 )
156 \&         \->clear();
157 .Ve
158 .SH "DESCRIPTION"
159 .IX Header "DESCRIPTION"
160 Test::MockObject::Extends lets you mock one or more methods of an existing
161 object or class.  This can be very handy when you're testing a well-factored
162 module that does almost exactly what you want.  Wouldn't it be handy to take
163 control of a method or two to make sure you receive testable results?  Now you
164 can.
165 .SH "METHODS"
166 .IX Header "METHODS"
167 .ie n .IP """new( $object | $class )""" 4
168 .el .IP "\f(CWnew( $object | $class )\fR" 4
169 .IX Item "new( $object | $class )"
170 \&\f(CW\*(C`new()\*(C'\fR takes one optional argument, the object or class to mock.  If you're
171 mocking a method for an object that holds internal state, create an appropriate
172 object, then pass it to this constructor.  \fB\s-1NOTE:\s0\fR this will modify the object
173 in place.
174 .Sp
175 If you're mocking an object that does not need state, as in the cases where
176 there's no internal data or you'll only be calling class methods, or where
177 you'll be mocking all of the access to internal data, you can pass in the name
178 of the class to mock partially.
179 .Sp
180 If you've not yet loaded the class, this method will try to load it for you.
181 This may fail, so beware.
182 .Sp
183 If you pass no arguments, it will assume you really meant to create a normal
184 \&\f(CW\*(C`Test::MockObject\*(C'\fR object and will oblige you.
185 .Sp
186 Note that if you pass a class, the object returned will appear to be an
187 instance of that class; \fIthis does not mock the class itself\fR.
188 .ie n .IP """mock( $methodname, $sub_ref )""" 4
189 .el .IP "\f(CWmock( $methodname, $sub_ref )\fR" 4
190 .IX Item "mock( $methodname, $sub_ref )"
191 See the documentation for Test::MockObject for all of the ways to mock methods
192 and to retrieve method logging information.  These methods return the invocant,
193 so you can chain them.
194 .ie n .IP """unmock( $methodname )""" 4
195 .el .IP "\f(CWunmock( $methodname )\fR" 4
196 .IX Item "unmock( $methodname )"
197 Removes any active mocking of the named method.  This means any calls to that
198 method will hit the method of that name in the class being mocked, if it
199 exists.  This method returns the invocant, you can chain it.
200 .ie n .IP """isa( $class )""" 4
201 .el .IP "\f(CWisa( $class )\fR" 4
202 .IX Item "isa( $class )"
203 As you'd expect from a mocked object, this will return true for the class it's
204 mocking.
205 .SH "INTERNAL METHODS"
206 .IX Header "INTERNAL METHODS"
207 To do its magic, this module uses several internal methods:
208 .ie n .IP "* ""check_class_loaded( $parent_class )""" 4
209 .el .IP "* \f(CWcheck_class_loaded( $parent_class )\fR" 4
210 .IX Item "check_class_loaded( $parent_class )"
211 This verifies that you have the mockee defined.  If not, it attempts to load
212 the corresponding module for you.
213 .ie n .IP "* ""gen_autoload( $extended )""" 4
214 .el .IP "* \f(CWgen_autoload( $extended )\fR" 4
215 .IX Item "gen_autoload( $extended )"
216 Returns an \s-1AUTOLOAD\s0 subroutine for the mock object that checks that the
217 extended object (or class) can perform the requested method, that
218 Test::MockObject can perform it, or that the parent has an appropriate
219 \&\s-1AUTOLOAD\s0 of its own.  (It should have its own \f(CW\*(C`can()\*(C'\fR in that case too
220 though.)
221 .ie n .IP "* ""gen_can( $extended )""" 4
222 .el .IP "* \f(CWgen_can( $extended )\fR" 4
223 .IX Item "gen_can( $extended )"
224 Returns a \f(CW\*(C`can()\*(C'\fR method for the mock object that respects the same execution
225 order as \f(CW\*(C`gen_autoload()\*(C'\fR.
226 .ie n .IP "* ""gen_isa( $extended )""" 4
227 .el .IP "* \f(CWgen_isa( $extended )\fR" 4
228 .IX Item "gen_isa( $extended )"
229 Returns an \f(CW\*(C`isa()\*(C'\fR method for the mock object that claims to be the
230 \&\f(CW$extended\fR object appropriately.
231 .ie n .IP "* ""gen_get_parents( $extended )""" 4
232 .el .IP "* \f(CWgen_get_parents( $extended )\fR" 4
233 .IX Item "gen_get_parents( $extended )"
234 Returns a \f(CW\*(C`_\|_get_parents()\*(C'\fR method for the mock object that claims to be the
235 \&\f(CW$extended\fR object appropriately.
236 .ie n .IP "* ""gen_package( $extended )""" 4
237 .el .IP "* \f(CWgen_package( $extended )\fR" 4
238 .IX Item "gen_package( $extended )"
239 Creates a new unique package for the mock object with the appropriate methods
240 already installed.
241 .ie n .IP "* ""get_class( $invocant )""" 4
242 .el .IP "* \f(CWget_class( $invocant )\fR" 4
243 .IX Item "get_class( $invocant )"
244 Returns the class name of the invocant, whether it's an object or a class name.
245 .SH "CAVEATS"
246 .IX Header "CAVEATS"
247 There may be some weird corner cases with dynamically generated methods in the
248 mocked class.  You really should use subroutine declarations though, or at
249 least set \f(CW\*(C`can()\*(C'\fR appropriately.
250 .PP
251 There are also potential name collisions with methods in this module or
252 \&\f(CW\*(C`Test::MockObject\*(C'\fR, though this should be rare.
253 .SH "AUTHOR"
254 .IX Header "AUTHOR"
255 chromatic, <chromatic at wgz dot org>
256 .PP
257 Documentation bug fixed by Stevan Little.  Additional \s-1AUTOLOAD\s0 approach
258 suggested by Adam Kennedy.  Other bugs reported by Paul the Nomad and Praveen
259 Ray.  Thank you all!
260 .SH "BUGS"
261 .IX Header "BUGS"
262 No known bugs.
263 .SH "COPYRIGHT"
264 .IX Header "COPYRIGHT"
265 Copyright (c) 2004 \- 2008, chromatic.  All rights reserved.  You may use,
266 modify, and distribute this module under the same terms as Perl 5.10