I am creating a set of small Perl programs which will be run like a CLI. I want all of them to share some features, eg. same input/output format (probably JSON). I also want each component to be black-box testable with mock arguments. This is what I have so far:
A number of modules
actionA.pm
,actionB.pm
...actionZZZ.pm
, one for each component/operation. All of them willuse Moose
and should have asub run {...}
which will receive a data hasref/object with the operation's input parameters, and any handle (database, filesystem, whatever) they need to use, and return a data hashref/object with the operation's output parameters.A Moose role which
requires 'run'
and is consumed by everyactionX.pm
module, forcing them to implementrun
.Additional Moose roles and/or superclasses for certain subsets of the
actionX.pm
modules, so they can consume them to specify wether they need theirrun
method to be provided with a database handler, a filesystem handler, etc.A common Moose superclass (don't know if this really needs to be either Moose nor a superclass, just want this to be a fairly simple one-liner on each
actionX.pm
), let's call itabstractAction.pm
, for all of theactionX.pm
classes, which converts them into some sort of Modulino (see below).
What I want to achieve with this is that, when I run perl actionX.pm arguments
from command line, some code in abstractAction.pm
will:
Read JSON/whatever from
@ARGV
and convert it to Perl data structures.This part is not clear: know that it was called from/as
actionX
, so it knows that ifactionX
consumes roleneedDB
, it will need to get a database handler to pass it torun
, etc.Call
actionX->run()
passing the data object and any handler obtained at step 2.
I tried using both run()
and __PACKAGE__->run()
in abstractAction.pm
, but it calls the superclass method, not the child's. Is there any way I can know the child's package name from the parent? That doesn't even sound good. Is there a better way to do what I am trying to achieve?
I know I could simply do perl abstractAction.pm actionX arguments
instead of perl actionX.pm arguments
and call it a day, but I'd rather not.