Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Subclassing a class that uses an internal dispatch table

by TOD (Friar)
on Oct 30, 2007 at 06:30 UTC ( [id://647983]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Subclassing a class that uses an internal dispatch table
in thread Subclassing a class that uses an internal dispatch table

yes, you're right. both $cmd and @args will be received through the socket. hmm... what about this one:
#!/usr/bin/perl -w { package Net::SMTP::Server::Client2::Subclass; use strict; use vars qw/@ISA/; use Net::SMTP::Server::Client2; @ISA = qw/Net::SMTP::Server::Client2/; my %_pcmds = ( HELO => \do { print STDERR "hello\n" } ); our $eval_command = sub { my ($self, $cmd, @args) = @_; my $hash = (__PACKAGE__ =~ /Subclass$/) ? '$_pcmds' : '$ +_cmds'; $cmd = "&{$hash"."{$cmd}}(\$self, \\\@args)"; eval $cmd or return(defined($self->{MSG})); }; &Net::SMTP::Server::Client2::eval_command = \$eval_command; sub new { my ($class, $sock) = @_; my $self = $class->SUPER::new($sock); bless $self, __PACKAGE__; } sub get_message { my $self = shift; my ($cmd, @args); # [...} # do everything the super class does, up to this point: if (exists $_pcmds{$cmd}) { $eval_command->($self, $cmd, @args); } else { $self->SUPER::eval_command($cmd, @args); } } 1; }
i've never done that before, but at least the compiler doesn't complain.
--------------------------------
masses are the opiate for religion.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-24 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found