Evented-API-Engine

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


 Dependency resolution

    API Engine automatically resolves dependencies of both modules and
    normal Perl packages. It loads and unloads dependencies in the proper
    order. It is also possible to specify that a submodule is automatically
    loaded and unloaded in conjunction with some top-level module.

 Event management

    API Engine is Evented in that it tracks all Evented::Object callbacks
    attached from within modules and automatically removes them upon
    unloading. This allows you to employ events excessively without
    constantly worrying about their eventual disposal.

METHODS

 Evented::API::Engine->new(%opts)

    Creates a new instance of the Evented API Engine. This single object
    will be used throughout the life of the application.

README.md  view on Meta::CPAN

### Dependency resolution

API Engine automatically resolves dependencies of both modules and normal Perl
packages. It loads and unloads dependencies in the proper order. It is also
possible to specify that a submodule is automatically loaded and unloaded in
conjunction with some top-level module.

### Event management

API Engine is *Evented* in that it tracks all
[Evented::Object](https://github.com/cooper/evented-object) callbacks attached
from within modules and automatically removes them upon unloading. This allows
you to employ events excessively without constantly worrying about their
eventual disposal.

lib/Evented/API/Engine.pm  view on Meta::CPAN

=head2 Dependency resolution

API Engine automatically resolves dependencies of both modules and normal Perl
packages. It loads and unloads dependencies in the proper order. It is also
possible to specify that a submodule is automatically loaded and unloaded in
conjunction with some top-level module.

=head2 Event management

API Engine is I<Evented> in that it tracks all
L<Evented::Object> callbacks attached
from within modules and automatically removes them upon unloading. This allows
you to employ events excessively without constantly worrying about their
eventual disposal.

=head1 METHODS

=head2 Evented::API::Engine->new(%opts)

Creates a new instance of the Evented API Engine. This single object will be
used throughout the life of the application.

lib/Evented/API/Events.pm  view on Meta::CPAN

    $mod->on(set_variables =>
        \&mod_default_set_variables, 'api.engine.setVariables');

    # make the module a class monitor of each package
    Evented::Object::add_class_monitor($_, $mod) for $mod->packages;

    # registered a callback
    $mod->on('monitor:register_callback' =>
        \&mod_event_registered, 'api.engine.eventTracker.register');

    # deleted all callbacks for an event
    $mod->on('monitor:delete_event' =>
        \&mod_event_deleted, 'api.engine.eventTracker.deleteEvent');

    # deleted a specific callback
    $mod->on('monitor:delete_callback' =>
        \&mod_callback_deleted, 'api.engine.eventTracker.deleteCallback');

    # module unloaded
    $mod->on(unload => \&mod_unloaded,
        'api.engine.eventTracker.unload');

lib/Evented/API/Events.pm  view on Meta::CPAN

    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");
    $mod->list_store_remove_matches('managed_events', sub {
        my $e = shift;
        return 1 if not defined $e->[0];        # disposed, delete
        return unless $eo         == $e->[0];   # wrong eo
        return unless $event_name eq $e->[1];   # wrong event
        return 1;                               # match, delete
    });
}

# on callback delete, remove from managed event list

lib/Evented/API/Events.pm  view on Meta::CPAN

    foreach my $e ($mod->list_store_items('managed_events')) {
        my ($eo, $event_name, $name) = @$e;
        my $ref = ref $eo;

        # this is a weak reference --
        # if undefined, it was disposed of
        return unless $eo;

        # first one
        if (!$indented) {
            $mod->Debug('Destroying managed event callbacks');
            $mod->api->{indent}++;
            $indented++;
        }

        # delete this callback
        $eo->delete_callback($event_name, $name);
        $mod->Debug("Event: $event_name ($name) deleted from $ref");

    }
    $mod->api->{indent}-- if $indented;



( run in 0.323 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )