The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MooseX::Role::MissingMethodUtils - Getting rid of boilerplate AUTOLOAD stuff

VERSION

version 0.02

SYNOPSIS

package Foo;
use Moose;

with 'MooseX::Role::MissingMethodUtils';

sub method_missing {
    my ($self, $method_name, @params) = @_;

    if ( $method_name eq 'do_this' ) {
        Delegator->do_this; 
    }
}

sub responds_to {
    my ($self, $method_name) = @_;

    if ( $method_name =~ /foo/ )
    {
        return sub {
            print "Bar";
        }
    }
}

DESCRIPTION

This role will now introduce a method named method_missing. This method is called via AUTOLOAD as a last resort in the calling chain.

Three parameters will be passed in to help with delegation: ref to self,method name, and parameters.

CALLBACKS

method_missing

Call back method that is called during the AUTOLOAD phase. It's unable to find a method and will call this method_missing as last resort for delegation.

responds_to

Call back method that is called during a "can" call. This method needs to just return a sub ref.

METHODS

AUTOLOAD

Just does all the boilerplate autoloading stuff. Will call "method_missing"

can

A subclass of can, will call "responds_to" if nothing is found in super.

AUTHOR

Logan Bell <loganbell@gmail.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by Logan Bell.

This is free software, licensed under:

The (three-clause) BSD License