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

Re: subclassing: how to design my module

by stevieb (Canon)
on Feb 09, 2018 at 15:11 UTC ( [id://1208838]=note: print w/replies, xml ) Need Help??


in reply to subclassing: how to design my module

Congratulations Discipulus!

Without seeing an overview of all the various pieces, it's hard to come up with the best scenario here, so anything I say here is just off the top of my head.

In Win32::Event2Log, you could use the Engine as a base class, and in the Engine, you could use (or optionally require at runtime depending on the user's selection). Then, for example, if a user wants a specific "type" (ie. Reader, or wrapper for the binary):

my $obj = Win32::Event2Log->new(engine => 'type');

Then, in the constructor above:

use 'base' Win32::Event2Log::Engine; sub new { my ($class, %args) = @_; my $self = bless {%args}, $class; # select_engine inherited return $self->select_engine($self->{engine}); }

In Engine

use Win32::Event2Log::Reader; use Win32::Event2Log::Wevtutil; sub select_engine { shift; # throw away Event2Log object, unless needed/wanted my ($engine) = @_; my %engines = ( reader => sub { return Win32::Event2Log::Reader->new(...); }, wrapper => sub { return Win32::Event2Log::Wevtutil->new(...); +}, ); $engines{$engine}->(); }

Very much untested, and again, I'm a bit confused as to how the whole thing ties together, so this is just one example of what can be done here. If you add more functionality in the future, you'd just need to modify Engine, as the Event2Log module simply passes the "type" along as an argument. Engine can take care of managing the actual engines, as it probably should.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-19 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found