יובל קוג'מן (Yuval Kogman)

NAME

Object::Meta::Plugin::Useful::Meta - a subclass of Object::Meta::Plugin::Useful and Object::Meta::Plugin::Host, base class for hosts which are plugins.

SYNOPSIS

        my $host = Object::Meta::Plugin::Host->new();
        my $plugin = Object::Meta::Plugin::Useful::Meta::new();

        $plugin->plug(MyPlug->new());   # of course, there's no point if
                                                                        # this isn't more interesting

        $host->plugin($plugin);

DESCRIPTION

This is an Object::Meta::Plugin::Host and more. It provides the necessary methods to treat a host as a plugin. It is not the most elegant solution, see CAVEATS.

CAVEATS

  • Somewhat defies the purpose of plugging things in. It is possible (and even tested for) to plug a plugin into a host, and have that plugin provide plugin capabilities. Such an implementation would look like this:

            package SuperPlugin;
    
            use strict;
            use warnings;
    
            use base 'Object::Meta::Plugin::Useful::Generic';
    
            sub new {
                    my $pkg = shift;
                    my $self = $pkg->SUPER::new(@_);
                    $self->export(/init exports/);
            };
    
            sub init {
                    my $self = shift;
    
                    if ($self->can("super")){ # if we're part of a context, we're called from a host
                            unshift @_, $self->super; &init; # switch self, and rerun
                    } else {
                            $self->SUPER::init(@_); # goto the superclass (Object::Meta::Plugin::Useful::Generic) init.
                    }
            }
    
            sub exports { # if $self->can(super) return self->super->methods, whatever. Otherwise, export self as a plugin.
                    my $self = shift;
    
                    if ($self->can("super")){ # plugged in
                            keys %{ $self->super->methods }; # return the method names for the host
                    } else {
                            $self->SUPER::exports(@_); # Object::Meta::Plugin::Useful::Generic::exports
                    }
            }

COPYRIGHT & LICENSE

        Copyright 2003 Yuval Kogman. All rights reserved.
        This program is free software; you can redistribute it
        and/or modify it under the same terms as Perl itself.

AUTHOR

Yuval Kogman <nothingmuch@woobling.org>

SEE ALSO

Object::Meta::Plugin, Object::Meta::Plugin::Useful, Object::Meta::Plugin::Useful::Generic, Object::Meta::Plugin::Useful::Greedy.