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

Re: The costs of packages

by Beechbone (Friar)
on Sep 18, 2003 at 20:31 UTC ( [id://292515]=note: print w/replies, xml ) Need Help??


in reply to The costs of packages

Is there any real need to use classes at all? You could just use one class and store the information which C-class it is for inside.

example:

package My::Types; sub new { my $pclass = shift; my $cclass = shift; my $cself = $pclass->readFromData($cclass); my $pself = { cself => $cself, cclass => $cclass }; return bless $pself, ref($pclass)||$pclass; } sub isSame { my $pclass = shift; my $other = shift; return undef unless $other->CORE::isa(__PACKAGE__); return $other->{cclass} eq $pself->{cclass}; } sub getNumberOfParams { my $pself = shift; my $cself = $pself->{cself}; return $cself->{noOfParm}; } ... package main; $a = My::Types->new('printf'); print $a->getNumberOfParams();
(untested code)

Update: Oops, I coded an isSame() method, not an isa(). Renamed it to avoid misunderstandings...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://292515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found