Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
That may mean Zaxo had a different application in mind (where each variable had different constraints, and the need to define a factory function would have just made the module harder to use) . . .

You're exactly right about that. The original idea was just a bit of implementation to demonstrate validation for lvalue closures. My initial real application was to retrofit validation and detainting to cgi form processing scripts. No commonality was assumed for the variable types. It was later that I noticed more general applications for the module.

The idea of a factory-like method for constraining lists of variables is a good one. I'll add it to the TODO list. Here's an untested first cut at it:

use Tie::Constrained; sub Tie::Constrained::tiethese { my $self = shift; map {tie $_, 'Tie::Constrained', $self} @_; } my $integer = Tie::Constrained->new( sub { $_[0] =~ /^[+-]?\d+$/; } ); my ($i,$j,$k,$l); $integer->tiethese($i,$j,$k,$l);
As diotalevi said, functions return lists of values, not variables, so a method to tie a bunch of variables pretty much needs to be handed the variables and work with their aliases. You may not have noticed the constructor for unbound Tie::Constrained objects. I put that in to take the anonymity out of the subtypes and allow more readable ties with often-used constraints.

After Compline,
Zaxo


In reply to Re^3: Returning a tied scalar by Zaxo
in thread Returning a tied scalar by MarkusLaker

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 pondering the Monastery: (4)
As of 2024-04-19 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found