On Fri, Oct 26, 2012 at 03:29:27PM -0700, Karen Etheridge wrote:
> On Thu, Oct 25, 2012 at 04:05:05PM +0100, David Cantrell wrote:
> > I'm liberating some code that we use at work.  A first cut at CPAN-
> > ising it is here (yes, I know it has no tests yet):
> >   https://github.com/DrHyde/perl-Devel-Mockable
> > What do people think?
> I just took a quick glance while I had a minute, so this isn't very
> in-depth:
> - our::way: is that a local pragma? it isn't on cpan.

Ah, good catch.  That's our internal shortcut at work for
  use strict;
  use warnings;
  bunch of other stuff

I'll kill that right now.

But for anyone else paying attention, I'm not asking for code review.
I'll write tests that will catch silly errors like that.  I'm interested
in the name and the concept.

> - instead of manually writing into the symbol table, use one of the export
>   modules: Exporter, Sub::Exporter, Exporter::Declare etc.

Why?  No point adding a dependency for something so trivial.

> - I'm not sure if this belongs in the Devel namespace - someone else with
>   better knowledge of the nomenclature would be better able to say.

Nor am I :-)

> How does this add value above simply storing a class name in an accessor
> (e.g. a Class::Accessor field or Moose attribute)?  In moose, I could do
> this:

Well, it gives you the reset method so you can *temporarily* override
it.  And while the examples I gave are all storing class names, you
could have something more complex there - an object a code-ref,
anything.

> has useragent => ( is => 'ro', isa => 'Str', default => 'LWP::UserAgent' );
> 
> and then in testing, simply construct my class as:
> my $obj = Foo->new(..., useragent => 'Test::LWP::UserAgent');
> ...to swap out its implementation with something that is mockable.

That becomes unwieldy once you have more than one or two things to mock,
even ignoring the lack of an easy way of only doing it temporarily.

-- 
David Cantrell | Bourgeois reactionary pig

You don't need to spam good porn

Reply via email to