Have a look at this, it may be the sort of thing you are looking for:

package OO; my $properties = { 'user' => [ qr/^[a-zA-Z0-9]+$/, 'Username may only contain alphanu +meric characters' ], 'password' => [ qr/^[a-zA-Z0-9]+$/, 'Password may only contain alp +hanumeric characters' ], 'key' => [ qr/^[a-fA-F0-9]+$/, 'Key may only contain A-F alphanume +ric characters' ], }; $o = OO->new( user => 'username' ); $o->password( 'secret' ); $o->key( '***Invalid' ); $o->no_exist( 'foo' ); print "Password: ", $o->password(), $/; print "Input errors:\n" . $o->error() if $o->error(); use Data::Dumper; print Dumper $o; sub new { my $class = shift; my $self = { error => '' }; bless $self, $class; $self->init(@_) if @_; return $self; } sub init { my ( $self, %props ) = @_; for my $prop ( keys %props ) { my $value = $props{$prop}; $self->$prop( $value ); } } sub AUTOLOAD { my ( $self, $value ) = @_; my ( $method ) = $AUTOLOAD =~ m/::([^:]+)$/; if ( $properties->{$method} ) { if ( defined $value ) { # its a set method if ( $value =~ m/$properties->{$method}->[0]/ ) { $self->{$method} = $value; } else { $self->error( $properties->{$method}->[1] . "\n" ); } } else { # we have a get method return $self->{$method}; } } else { $self->error("Unknown method $method called from " . (join ' ' +, caller()) . "\n" ); } } sub error { my ( $self, $error ) = @_; $self->{error} .= $error if $error; return $self->{error}; } __DATA__ Password: secret $VAR1 = bless( { 'error' => 'Key may only contain A-F alphanumeric cha +racters Unknown method no_exist called from OO C:\\PROGRA~1\\PERLBU~1\\debug\\ +oo 15 ', 'password' => 'secret', 'user' => 'username' }, 'OO' ); Input errors: Key may only contain A-F alphanumeric characters Unknown method no_exist called from OO C:\PROGRA~1\PERLBU~1\debug\oo 1 +5

cheers

tachyon


In reply to Re: Capturing Method Call, And Relaying. by tachyon
in thread Capturing Method Call, And Relaying. by Revelation

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.