A
Andrew V. Tkachenko
Hello.
I'm a bit confused with the following problem:
Lets pretend that I have three modules:
###############
package myDaemon;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = ref($proto) ? $proto : {};
bless ($self, $class);
}
sub request {
my $self = shift;
my $data;
# some useful things like prepare $data content etc.
$self->_send_request($data);
}
sub _send_request {}
1;
#####################
package myDaemon::INET;
use strict;
use IO::Socket::INET;
our @ISA = qw/myDaemon/;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
# some configuration steps for INET socket
my $self = bless $proto->SUPER::new(@_), $class;
}
sub _send_request {
my ($self, $data) = @_;
# send $data via INET socket
}
1;
######################
package myDaemon::UNIX;
use strict;
use IO::Socket::UNIX;
our @ISA = qw/myDaemon/;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
# some configuration steps for UNIX socket
my $self = bless $proto->SUPER::new(@_), $class;
}
sub _send_request {
my ($self, $data) = @_;
# send $data via UNIX socket
}
1;
######################
Now I need to add more functionality to myDaemon package: I
need to track all requests and store them in some way
I think about overload myDaemon 'request' method:
##########################
package myLogDaemon;
use strict;
use myDaemon;
our @ISA = qw/myDaemon/;
sub request {
my $self = shift;
# dogin some logging
return $self->SUPER::request(@_);
}
###########################
But. How can I call myDaemon::Socket::INET->new in a way wich will let
me use overloaded 'request' method ?
Seems like I'm absolutely wrong with OO Perl but can't imagine
how to solve this problem
Any advice will be greatly appreciated.
Andrew.
I'm a bit confused with the following problem:
Lets pretend that I have three modules:
###############
package myDaemon;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = ref($proto) ? $proto : {};
bless ($self, $class);
}
sub request {
my $self = shift;
my $data;
# some useful things like prepare $data content etc.
$self->_send_request($data);
}
sub _send_request {}
1;
#####################
package myDaemon::INET;
use strict;
use IO::Socket::INET;
our @ISA = qw/myDaemon/;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
# some configuration steps for INET socket
my $self = bless $proto->SUPER::new(@_), $class;
}
sub _send_request {
my ($self, $data) = @_;
# send $data via INET socket
}
1;
######################
package myDaemon::UNIX;
use strict;
use IO::Socket::UNIX;
our @ISA = qw/myDaemon/;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
# some configuration steps for UNIX socket
my $self = bless $proto->SUPER::new(@_), $class;
}
sub _send_request {
my ($self, $data) = @_;
# send $data via UNIX socket
}
1;
######################
Now I need to add more functionality to myDaemon package: I
need to track all requests and store them in some way
I think about overload myDaemon 'request' method:
##########################
package myLogDaemon;
use strict;
use myDaemon;
our @ISA = qw/myDaemon/;
sub request {
my $self = shift;
# dogin some logging
return $self->SUPER::request(@_);
}
###########################
But. How can I call myDaemon::Socket::INET->new in a way wich will let
me use overloaded 'request' method ?
Seems like I'm absolutely wrong with OO Perl but can't imagine
how to solve this problem
Any advice will be greatly appreciated.
Andrew.