selfvars::autoload - Turn missing_sub(...) into $_[0]->missing_sub(...) implicitly


selfvars documentation  | view source Contained in the selfvars distribution.

Index


NAME

Top

selfvars::autoload - Turn missing_sub(...) into $_[0]->missing_sub(...) implicitly

SYNOPSIS

Top

    use Mojolicious::Lite; # The raison d'être for this module...

    # Import $self, @args, %opts and %hopts into your package;
    # see "perldoc selfvars" for import options and usage.
    use selfvars::autoload;

    # Normal invocation with two "$self"s
    get '/' => sub {
        my $self = shift;
        $self->render(text => 'Hello World!');
    };

    # It's OK to omit "my $self = shift":
    get '/selfish' => sub {
        $self->render(text => 'Hello World!');
    };

    # It's OK to omit the "$self->" part too!
    get '/selfless' => sub {
        render(text => 'Hello World!');
    };

    # dance!
    app->start;

DESCRIPTION

Top

This module exports four special variables: $self, @args, %opts and %hopts; see selfvars for the full description and import options.

In addition to that, this module sets up an AUTOLOAD subroutine in the importing package, so any calls to missing functions becomes a method call with $_[0] as the invocant.

If $_[0] is not present, then we raise an Undefined subroutine exception as usual.

The net effect is that we can start writing Mojolicious apps with Dancer syntax. :-)

DEPENDENCIES

Top

None.

SEE ALSO

Top

selfvars, Mojolicious, Dancer

AUTHORS

Top

唐鳳 <cpan@audreyt.org>

CC0 1.0 Universal

Top

To the extent possible under law, 唐鳳 has waived all copyright and related or neighboring rights to selfvars.

This work is published from Taiwan.

http://creativecommons.org/publicdomain/zero/1.0


selfvars documentation  | view source Contained in the selfvars distribution.