What I want is:
I'm working on a module to allow me create objects on the fly (I know there are a bunch of cpan modules that does exactly the same and better, but I was wondering how would that be, and also considered that a good learning experience)
The point is that I'm using something like this (On my main class):
sub AUTOLOAD {
my $_call = our $AUTOLOAD;
$_call =~ s/.*:://;
my $self = shift;
my $param = shift;
...
$self->{$_call} = $_param || return $self->{$_call};
}
So far, so good. But the problem is, that at some point, when I initialize a 'new' object, I define for it a list of available parameters, which will be then used as that object method.
So, what I want is to raise a warning when I try to do something like
my $o = Foo->new(); #create new object
$o->Available_Param_List(["one", "two"]); #methods that should be avai
+lable to $o
$o->one('this will work ok');
$o->nope('this should print a warn on saying that nope is not availabl
+e for $o');
I want to avoid things like passing the var name to the constructor function or things like that... Thats why I been thinking that *maybe* there was a way to know the name of the variable that called to a package.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.