Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Help Name This Module

by Corion (Patriarch)
on Apr 14, 2001 at 01:36 UTC ( [id://72494]=note: print w/replies, xml ) Need Help??


in reply to Help Name This Module

I like this module, and Ensure is an appropriate name IMO, but Loop::Invariant describes more clearly what the programmer intends to happen. Contract is a close third, while I find Assert unexpected in the sense that the program dosen't die when an assertion fails.

But I have some problems with running your module :

  1. It dosen't run under Perl 5.5.3 (ActiveState Perl build 517)
  2. Under Perl 5.6.0 (IndigoPerl), I get Can't use string ("") as a subroutine ref while "strict refs" in use at Ensure.pm line 56. as an error in the Ensure::Scalar::FETCH sub. I think this comes from a conflict in execution order as follows :
    1. Ensure::using is called to tie the scalar, and sets up the Ensure::Scalar::FETCH handler.
    2. Ensure::ensure is called, and itself calls tied($$_), which in turn results in Ensure::Scalar::FETCH being called.
    3. Ensure::Scalar::FETCH is called and runs into the undef, as the handlers have not yet been set up (from within Ensure::ensure).

The quick fix to me was a small change to the Ensure::Scalar module as follows :

sub TIESCALAR { my ($class, $val) = @_; my $ref = [ $val, "setup", "setup" ]; bless $ref, $class; return $ref; } sub FETCH { my $self = shift; my $val = $self->[0]; if (ref($self->[1]) eq 'CODE') { die "[Ensure]\n" unless $self->[1]->(); }; return $val; }
This fix would have to be repeated for the other modules (or maybe isn't necessary at all with Perl 5.6.1), and I'm not sure if my fix is really a fix and dosen't introduce more errors, as this is the first time I've dabbled with tie :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found