I am new to Muse. I have to create an object that should load several plugins. The structure looks like this:
- Main object -> some common functions
- Plugins → extensions for the main object
Plugins are located in a separate folder on the server. The main object is to load plugins, initialize them and store the object by itself. Each plugin return value must go through the main object. Because the main object must convert every return value in the JSON structure for the caller.
I would call something like this:
my $main_obj = Main->new(); $main_obj->plugin('MainExtention')->get_title();
Here is my sample code:
The main object:
package Main; use Moose; has 'plugins' => ( is => 'rw', ); has 'title' => ( is => 'rw', isa => 'Str', reader => '_get_title', );
MainExtention plugin in the directory "/usr/local/apache/sites/.../Plugins":
package MainExtention; use Moose; has 'title' => ( is => 'rw', isa => 'Str', default => 'Default', ); sub get_title { return 'MainExtention Title'; } 1;
This works as follows:
my $main = Main->new(); my $plugins = $main->plugins(); print $plugins->{'MainExtention'}->get_title();
But this is not what I will have :) I will get the plugin return directly from the plugin, but from the main object. Does anyone have an idea? Second question: is there an easier way to download plugins? How?
source share