Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Slide form presentation

  • Loading branch information...
commit caf057e628689b5bc6361682d70120779c81b973 1 parent cd2273b
@exodist authored
View
2  lib/Mock/Quick/Presentation/slideA.pod
@@ -9,6 +9,6 @@ Mock::Quick::Presentation - Presentation of Mock::Quick to PDX.pm
This is a presentation for Mock::Quick. This presentation was written for the
portland perl mongers for the meeting on 04/13/2011.
-L<Next|Mock::Quick::Presentation::slideB>
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideB.pod>
=cut
View
214 lib/Mock/Quick/Presentation/slideB.pod
@@ -1,14 +1,5 @@
=pod
-=head1 NAME
-
-Mock::Quick::Presentation - Presentation of Mock::Quick to PDX.pm
-
-=head1 DESCRIPTION
-
-This is a presentation for Mock::Quick. This presentation was written for the
-portland perl mongers for the meeting on 04/13/2011.
-
=head1 QUICK OBJECTS
=over 4
@@ -48,208 +39,7 @@ Thats where quick objects come in:
"add_and_append works"
);
-=head2 METHOD AUTOVIVIFYING
-
-Sometimes you need to pass in an object that has more methods than you care to
-mock out, they only need to be present and return something.
-
-Thats where the next feature of Quick Objects comes in. Quick objects
-will autovivify methods as they are needed. The new methods will be read/write
-accessors.
-
- my $obj = qobj();
- $obj->foo( 'bar' );
- is( $obj->foo, 'bar', "foo attribute was set" );
- is(
- $obj->foo( 'baz' ),
- 'baz',
- "remembers and returns whatever argument you give it."
- );
-
-=head2 STRICT OBJECTS
-
-=over 4
-
-=item Autovivifying can be bad
-
-=item Autovivification has been reported as a bug in hashes
-
-For cases where you do not want autovivifying you can use strict objects. A
-strict object will not autovivify.
-
- my $obj = qstrict( foo => 'foo' );
- is( $obj->foo, 'foo' );
- dies_ok { $obj->bar } "no bar() method defined";
-
-=back
-
-=head3 But what if you want to change the specification later?
-
-Easy!
-
-in list context C<qobj> and C<qstrict> return both the new object, and a
-control object that provides a manipulation interface.
-
- my ( $obj, $control ) = qstrict( foo => 'foo' );
- $control->set_attributes( bar => 'bar' );
-
-=head3 Why not just provide a manipulation interface as a method on the object?
-
-because it might conflict with the api you are attempting to mock.
-
-=head2 CUSTOM METHODS
-
-More often than not you need to mock out methods more complicated than
-accessors. You can add them to your quick object in 2 ways.
-
-You can't just assign a coderef to an accessor, that would just result in an
-accessor that returns a coderef. This is important because there are cases
-where that is what you really want.
-
-The original way to create a custom method is the C<qmeth()> function.
-
- $obj->new_method( qmeth {
- my $self = shift;
- ...
- return 'whatever';
- });
-
-This will add a method that will be run next time you call
-C<$obj-E<gt>new_method>.
-
-Arguments will not be used to replace the method on the object like they would
-a in a get/set accessor.
-
-Some people have expressed displeasure with this API. C<qmeth {...}> seems too
-magical. The alternative is to use the control object.
-
- my ( $obj, $control ) = qobj(...);
- $control->set_methods( foo => sub { ... });
-
-=head2 CLEARING METHODS/ATTRIBUTES
-
-We have so far seen many ways to add methods, attributes and accessors to a
-quick object. But you can also clear them! This is particularly useful in
-strict objects where they will not autovivify back into existance.
-
-One again there are 2 ways to clear an attribute or method. The original way
-using the C<qclear> method, and the new way using the control object.
-
- # Remove the foo() attribute and any associated value/method
- $obj->foo( qclear() );
-
- # Remove a whole list of attributes
- $control->clear( qw/foo bar baz/ );
-
-=head2 CONTROL OBJECT
-
-The control object provides 2 additional methods.
-
-=over 4
-
-=item $control->strict( BOOL )
-
-Lets you toggle strict mode on and off for your object.
-
-=item $control->metrics
-
-Returns a hashref with all current attributes/methods as keys, the values
-associated with them are the counts of how many times that attribute has been
-called. Clearing an attribute will reset its metrics.
-
-=back
-
-=head1 MOCKING CLASSES
-
-Sometimes a quick object is not sufficient.
-
-=over 4
-
-=item The object you need to mock is instantiated inside the function you're testing
-
-=item You want to preserve the original class, but you need to override a subset of methods
-
-=item You want to replace the original class and prevent it from loading
-
-=item You want to implement a temporary but re-usable class specification
-
-=back
-
-=head2 TAKING OVER A CLASS
-
-The class is loaded, you want to change parts of it
-
-=over 4
-
-=item Take control of the class
-
- require Some::Package;
- my $control = qtakeover( 'Some::Package' );
-
-=item Have your way with it
-
- $control->override(
- foo => sub { ... }
- bar => sub { ... }
- );
-
-=item Restore the original method
-
- $control->restore( 'foo' );
-
-=item The original class is completely restored when the control object is destroyed.
-
- $control = undef;
-
-=back
-
-=head2 USURPING A CLASS
-
-The class is not loaded, you want to keep it that way, and put something in it's place.
-
-=over 4
-
-=item Create the package, %INC is updated for you to prevent the real one from loading.
-
- my $control = qimplement Some::Package => ( ... );
-
-=back
-
-=head3 arguments
-
-=over 4
-
-=item auto-create new()
-
- -with_new => 1,
-
-=item subclassing
-
- -subclass => $class || [ @CLASSES ],
-
-=item quickly generate attributes (read/write)
-
- -attributes => [qw/ foo bar baz /]
-
-=item simple return value methods
-
- method => 'value'
-
-=item custom methods
-
- do_it => sub { ... }
-
-=back
-
-The control object returned is identical to that from C<qtakeover()>.
-
-=head2 ANONYMOUS CLASSES
-
-An anonymous class is the same as userping a class, except instead of using a
-real package a temporary one is created.
-
- my $control = qclass( ... )
-
-Takes all the same arguments as qimplement.
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideC.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideA.pod>
=cut
View
24 lib/Mock/Quick/Presentation/slideC.pod
@@ -0,0 +1,24 @@
+=pod
+
+=head2 METHOD AUTOVIVIFYING
+
+Sometimes you need to pass in an object that has more methods than you care to
+mock out, they only need to be present and return something.
+
+Thats where the next feature of Quick Objects comes in. Quick objects
+will autovivify methods as they are needed. The new methods will be read/write
+accessors.
+
+ my $obj = qobj();
+ $obj->foo( 'bar' );
+ is( $obj->foo, 'bar', "foo attribute was set" );
+ is(
+ $obj->foo( 'baz' ),
+ 'baz',
+ "remembers and returns whatever argument you give it."
+ );
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideD.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideB.pod>
+
+=cut
View
37 lib/Mock/Quick/Presentation/slideD.pod
@@ -0,0 +1,37 @@
+=pod
+
+=head2 STRICT OBJECTS
+
+=over 4
+
+=item Autovivifying can be bad
+
+=item Autovivification has been reported as a bug in hashes
+
+For cases where you do not want autovivifying you can use strict objects. A
+strict object will not autovivify.
+
+ my $obj = qstrict( foo => 'foo' );
+ is( $obj->foo, 'foo' );
+ dies_ok { $obj->bar } "no bar() method defined";
+
+=back
+
+=head3 But what if you want to change the specification later?
+
+Easy!
+
+in list context C<qobj> and C<qstrict> return both the new object, and a
+control object that provides a manipulation interface.
+
+ my ( $obj, $control ) = qstrict( foo => 'foo' );
+ $control->set_attributes( bar => 'bar' );
+
+=head3 Why not just provide a manipulation interface as a method on the object?
+
+because it might conflict with the api you are attempting to mock.
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideE.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideC.pod>
+
+=cut
View
35 lib/Mock/Quick/Presentation/slideE.pod
@@ -0,0 +1,35 @@
+=pod
+
+=head2 CUSTOM METHODS
+
+More often than not you need to mock out methods more complicated than
+accessors. You can add them to your quick object in 2 ways.
+
+You can't just assign a coderef to an accessor, that would just result in an
+accessor that returns a coderef. This is important because there are cases
+where that is what you really want.
+
+The original way to create a custom method is the C<qmeth()> function.
+
+ $obj->new_method( qmeth {
+ my $self = shift;
+ ...
+ return 'whatever';
+ });
+
+This will add a method that will be run next time you call
+C<$obj-E<gt>new_method>.
+
+Arguments will not be used to replace the method on the object like they would
+a in a get/set accessor.
+
+Some people have expressed displeasure with this API. C<qmeth {...}> seems too
+magical. The alternative is to use the control object.
+
+ my ( $obj, $control ) = qobj(...);
+ $control->set_methods( foo => sub { ... });
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideF.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideD.pod>
+
+=cut
View
21 lib/Mock/Quick/Presentation/slideF.pod
@@ -0,0 +1,21 @@
+=pod
+
+=head2 CLEARING METHODS/ATTRIBUTES
+
+We have so far seen many ways to add methods, attributes and accessors to a
+quick object. But you can also clear them! This is particularly useful in
+strict objects where they will not autovivify back into existance.
+
+One again there are 2 ways to clear an attribute or method. The original way
+using the C<qclear> method, and the new way using the control object.
+
+ # Remove the foo() attribute and any associated value/method
+ $obj->foo( qclear() );
+
+ # Remove a whole list of attributes
+ $control->clear( qw/foo bar baz/ );
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideG.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideE.pod>
+
+=cut
View
24 lib/Mock/Quick/Presentation/slideG.pod
@@ -0,0 +1,24 @@
+=pod
+
+=head2 CONTROL OBJECT
+
+The control object provides 2 additional methods.
+
+=over 4
+
+=item $control->strict( BOOL )
+
+Lets you toggle strict mode on and off for your object.
+
+=item $control->metrics
+
+Returns a hashref with all current attributes/methods as keys, the values
+associated with them are the counts of how many times that attribute has been
+called. Clearing an attribute will reset its metrics.
+
+=back
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideH.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideF.pod>
+
+=cut
View
22 lib/Mock/Quick/Presentation/slideH.pod
@@ -0,0 +1,22 @@
+=pod
+
+=head1 MOCKING CLASSES
+
+Sometimes a quick object is not sufficient.
+
+=over 4
+
+=item The object you need to mock is instantiated inside the function you're testing
+
+=item You want to preserve the original class, but you need to override a subset of methods
+
+=item You want to replace the original class and prevent it from loading
+
+=item You want to implement a temporary but re-usable class specification
+
+=back
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideI.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideG.pod>
+
+=cut
View
34 lib/Mock/Quick/Presentation/slideI.pod
@@ -0,0 +1,34 @@
+=pod
+
+=head2 TAKING OVER A CLASS
+
+The class is loaded, you want to change parts of it
+
+=over 4
+
+=item Take control of the class
+
+ require Some::Package;
+ my $control = qtakeover( 'Some::Package' );
+
+=item Have your way with it
+
+ $control->override(
+ foo => sub { ... }
+ bar => sub { ... }
+ );
+
+=item Restore the original method
+
+ $control->restore( 'foo' );
+
+=item The original class is completely restored when the control object is destroyed.
+
+ $control = undef;
+
+=back
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideJ.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideH.pod>
+
+=cut
View
46 lib/Mock/Quick/Presentation/slideJ.pod
@@ -0,0 +1,46 @@
+=pod
+
+=head2 USURPING A CLASS
+
+The class is not loaded, you want to keep it that way, and put something in it's place.
+
+=over 4
+
+=item Create the package, %INC is updated for you to prevent the real one from loading.
+
+ my $control = qimplement Some::Package => ( ... );
+
+=back
+
+=head3 arguments
+
+=over 4
+
+=item auto-create new()
+
+ -with_new => 1,
+
+=item subclassing
+
+ -subclass => $class || [ @CLASSES ],
+
+=item quickly generate attributes (read/write)
+
+ -attributes => [qw/ foo bar baz /]
+
+=item simple return value methods
+
+ method => 'value'
+
+=item custom methods
+
+ do_it => sub { ... }
+
+=back
+
+The control object returned is identical to that from C<qtakeover()>.
+
+L<Next|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideK.pod>
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideJ.pod>
+
+=cut
View
14 lib/Mock/Quick/Presentation/slideK.pod
@@ -0,0 +1,14 @@
+=pod
+
+=head2 ANONYMOUS CLASSES
+
+An anonymous class is the same as userping a class, except instead of using a
+real package a temporary one is created.
+
+ my $control = qclass( ... )
+
+Takes all the same arguments as qimplement.
+
+L<Previous|https://github.com/exodist/Mock-Quick/blob/master/lib/Mock/Quick/Presentation/slideJ.pod>
+
+=cut
Please sign in to comment.
Something went wrong with that request. Please try again.