selfvars::autoload - Turn missing_sub(...) into $_[0]->missing_sub(...) implicitly
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;
This module exports four special variables: $self, @args, %opts and %hopts; see selfvars for the full description and import options.
$self
@args
%opts
%hopts
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.
AUTOLOAD
$_[0]
If $_[0] is not present, then we raise an Undefined subroutine exception as usual.
Undefined subroutine
The net effect is that we can start writing Mojolicious apps with Dancer syntax. :-)
None.
selfvars, Mojolicious, Dancer
唐鳳 <cpan@audreyt.org>
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
To install selfvars, copy and paste the appropriate command in to your terminal.
cpanm
cpanm selfvars
CPAN shell
perl -MCPAN -e shell install selfvars
For more information on module installation, please visit the detailed CPAN module installation guide.