Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 :-)


In reply to Re: Help Name This Module by Corion
in thread Help Name This Module by japhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-03-29 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found