NAME
selfvars::autoload - Turn missing_sub(...) into $_[0]->missing_sub(...) implicitly
SYNOPSIS
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
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
None.
SEE ALSO
AUTHORS
唐鳳 <cpan@audreyt.org>
CC0 1.0 Universal
To the extent possible under law, 唐鳳 has waived all copyright and related or neighboring rights to selfvars.
This work is published from Taiwan.