Devel-Decouple
view release on metacpan or search on metacpan
lib/Devel/Decouple.pm view on Meta::CPAN
is( TestMod::Baz::prohibit(), "defined by \$DD2" );
### POP
undef $DD2;
is( TestMod::Baz::inhibit(), 3 );
is( TestMod::Baz::prohibit(), 2 );
### And so on...
Caution should be exercised here as the C<Devel::Decouple> object instances are actually collections of stacks maintained for each function. It can become confusing to keep track of what behavior was specified in which objects and how those objects r...
=back
=head2 Redispatching
=over
For any function definition you provide you have access to the immediately previous code definition on the stack. This behavior is passed to your new function definition as a sub-ref in the first element of C<@_>. The remainder of C<@_> contains the ...
# Define a 'default_sub' that reports the arguments a function was called with
# and then delegates back to the previous behavior on the stack...
my $Decoupler = Devel::Decouple->new;
$Decoupler->decouple( 'My::Module',
default_sub, as { my $orig = shift;
warn ("'", caller(0))[3],
"' called with args: ",
join '=|=', @_;
$orig->(@_)}, # redispatch!
);
If you wish, you can redispatch to any arbitrary depth down the stack of function definitions in this way, continually passing the original arguments along until ultimately terminating at the original source function definition.
Combining the use of the stack and this re-dispatch mechanism is a powerful way to implement stack traces, data serialization, and other exploratory testing for I<all> the functions in a complex or convoluted name-space. C<Devel::Decouple> isn't just...
Using such a technique can help you to understand the behavior of legacy Perl code so that you can clear the seemingly insurmountable hurdle of writing the initial tests. By automating much of the exploratory analysis of dense code it can also aid yo...
=back
=head2 Devel::Decouple Testing Kata
=over
Red. Green. Refactor.
Helpful code snippets coming soon...
=back
=head1 CONFIGURATION AND ENVIRONMENT
Devel::Decouple requires no configuration files or environment variables.
=head1 BUGS AND LIMITATIONS
C<Devel::Decouple> does not currently identify imported symbols other than subroutines.
Please report any bugs or feature requests to <F<dev@namimedia.com>>.
=head1 AUTHOR
Montgomery Conner <F<mconner@cpan.org>>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2012, NamiMedia <F<dev@namimedia.com>>. All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
( run in 3.192 seconds using v1.01-cache-2.11-cpan-6fb7bf0f510 )