Evented-API-Engine
view release on metacpan or search on metacpan
lib/Evented/API/Engine.pm view on Meta::CPAN
# the Evented API Engine is in charge of loading and unloading modules.
# it also handles dependencies and feature availability.
#
package Evented::API::Engine;
use warnings;
use strict;
use 5.010;
use JSON::XS;
use Scalar::Util qw(weaken blessed);
use Module::Loaded qw(mark_as_loaded mark_as_unloaded is_loaded);
use Evented::Object;
use parent 'Evented::Object';
our $VERSION = '4.13';
use Evented::API::Module;
use Evented::API::Events;
use Evented::Object::Hax qw(set_symbol make_child);
lib/Evented/API/Engine.pm view on Meta::CPAN
# store dependecy module objects.
$mod->{dependencies} = [
map { $api->get_module($_) } # this definitely is an arrayref;
@{ $info->{depends}{modules} } # verified @ ->_load_module_requirements
];
# make the API Engine listen to the events of the module.
# hold a weak reference to the API engine.
$mod->add_listener($api, 'module');
weaken($mod->{api} = $api);
# here we fire an event which will export symbols for convenient use
# within the module packages. see Module.pm for defaults.
$mod->fire(set_variables => $_) for @pkgs;
# EVALUATE
#------------------------
my $return;
lib/Evented/API/Engine.pm view on Meta::CPAN
############################
### COMPANION SUBMODULES ###
############################
sub _add_companion_submodule_wait {
my ($api, $mod, $mod_name, $submod_name) = @_;
# postpone load until the companion is loaded.
# hold a weak reference to the module waiting.
my $waits = $api->{companion_waits}{$mod_name} ||= [];
my $ref = [ $mod, $submod_name ]; weaken($ref->[0]);
push @$waits, $ref;
# if it is already loaded, go ahead and load the submodule.
if (my $loaded = $api->get_module($mod_name)) {
return $api->_load_companion_submodules($loaded);
}
# false return indicates not yet loaded.
return;
}
lib/Evented/API/Events.pm view on Meta::CPAN
# default event responders
package Evented::API::Events;
use warnings;
use strict;
use 5.010;
use Evented::Object;
use parent 'Evented::Object';
use Scalar::Util qw(blessed weaken);
use Evented::Object::Hax qw(set_symbol);
our $VERSION = '4.13';
sub add_events {
my $mod = shift;
# default initialize handler
$mod->on(init => \&mod_default_init,
name => 'api.engine.initSubroutine',
lib/Evented/API/Events.pm view on Meta::CPAN
# permanent (not managed)
if ($cb->{permanent}) {
$mod->Debug("Permanent event: $event_name ($$cb{name}) registered to $ref");
return;
}
# store eo, event, and cb name
# hold weak reference to eo
my $e = [ $eo, $event_name, $cb->{name} ];
weaken($e->[0]);
$mod->list_store_add('managed_events', $e);
$mod->Debug("Event: $event_name ($$cb{name}) registered to $ref");
}
# on event delete, remove from managed event list
sub mod_event_deleted {
my ($mod, $fire, $eo, $event_name) = @_;
my $ref = ref $eo;
$mod->Debug("Event: $event_name (all callbacks) deleted from $ref");
lib/Evented/API/Module.pm view on Meta::CPAN
# Module represents an API module and provides an interface for managing one.
package Evented::API::Module;
use warnings;
use strict;
use 5.010;
use Evented::Object;
use parent 'Evented::Object';
use Scalar::Util qw(blessed weaken);
use List::Util qw(first);
our $VERSION = '4.13';
=head1 NAME
B<Evented::API::Module> - represents a module for use with
L<Evented::API::Engine>.
=head1 SYNOPSIS
lib/Evented/API/Module.pm view on Meta::CPAN
# call ->load_module with the search dir set to the
# parent module's main directory.
$mod->api->{indent}++;
my $ret = $mod->api->load_module($mod_name, [ $mod->{dir} ], 1);
$mod->api->{indent}--;
# add weakly to submodules list. hold weak reference to parent module.
if ($ret) {
my $a = $mod->{submodules} ||= [];
push @$a, $ret;
weaken($a->[$#$a]);
weaken($ret->{parent} = $mod);
}
return $ret;
}
=head2 $mod->unload_submodule($submod)
Unloads a submodule.
You do not have to call this in the parent module deinitializer. Only use this
( run in 0.738 second using v1.01-cache-2.11-cpan-65fba6d93b7 )