Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: subclassing: how to design my module

by stevieb (Abbot)
on Feb 09, 2018 at 15:11 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208838]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2018-06-21 14:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.