Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'd be interested to know more about your project and why you're considering going down that route. (See: When to use prototype inheritence?). I'm also interested in your experiences after the project.

There's also Class::SelfMethods by the same guy who wrote Class::Prototyped (Toby Everret). It's worth checking out as it had input from Damian Conway and Sean Burke. (Gleaned from the docs).

Unfortunately, I haven't got much practical experience with the modules so can't give you much advice. I'm considering emailing these authors to find out how the modules are being used and what the experience have been. I'll report back if I do.

I have my own, minimal version which is still being designed and debugged and may be ditched for a module implementation
The important bits follow, just 'new' and an AUTOLOAD accessor.

sub AUTOLOAD { # attrs my ($self) = @_; (my $attr = $AUTOLOAD) =~ s/^.*:://; return if $attr eq 'DESTROY'; return $self->{$attr} if(exists $self->{$attr}); return $self->{prototype}->$attr if(exists $self->{prototype}); } =item new Create a new Slot with prototyping. # class method my $proto = SD::Slot->new({ min_val => 1, max_val => 10 }); # $slot is blessed as an SD::Slot and has prototype = $proto my $slot = $proto->new({ min_val => 0 }); # $slot2 isa SD::Slot::Multi but still has prototype = $proto my $slot2 = SD::Slot::Multi->new({ prototype => $proto }); The parameter hashref is blessed into the appropriate class and returned. =cut sub new { my ($class, $proto, $self); # @_ processed conditionally if($class = ref $_[0]) { $proto = shift; # we have a prototype object } else { $class = shift; } $self = shift || {}; if(!exists $self->{prototype} && $proto) { $self->{prototype} = $proto; } bless $self => $class; } # example use (config) my %prototypes; $prototypes{int} = SD::Slot->new({ widget => 'textfield', constraints => [ \&SD::Constraints::integer_rx, \&SD::Constraints::min_val, \&SD::Constraints::max_val, ], }); $prototypes{int1_10} = $prototypes{int}->new({ prototype => $prototypes{int}, skip_warn => 1, min_val => 1, max_val => 10, }); my %slots; $slots{intelligence} = $prototypes{int1_10}->new({ name => 'intelligence', mandatory => 1, constraints => [ # add extra constraint @{ $prototypes{int}->constraints }, sub { $_[1] % 2 or die E->new( "Not an odd number '$_[1]'") }, ], });

Brad


In reply to Re: Class::Classless vs. Class::Prototyped by bsb
in thread Class::Classless vs. Class::Prototyped by John M. Dlugosz

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 rifling through the Monastery: (5)
As of 2024-03-28 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found