Skip to content

Commit

Permalink
fixed a few plugin examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 4, 2012
1 parent 15b474f commit c273e15
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/generate/plugin.pm
Expand Up @@ -69,7 +69,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
<% %>=head2 C<register>
$plugin->register;
$plugin->register($app);
Register plugin in L<Mojolicious> application.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Plugin/Charset.pm
Expand Up @@ -8,7 +8,7 @@ sub register {
my ($self, $app, $conf) = @_;

# Change default charset on all layers
return unless my $c = ($conf || {})->{charset};
return unless my $c = $conf->{charset};
$app->types->type(html => "text/html;charset=$c");
$app->renderer->encoding($c);
$app->hook(before_dispatch => sub { shift->req->default_charset($c) });
Expand Down Expand Up @@ -52,7 +52,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app, $conf);
Register plugin hooks in L<Mojolicious> application.
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Plugin/Config.pm
Expand Up @@ -34,7 +34,6 @@ sub parse {

sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# Config file
my $file = $conf->{file} || $ENV{MOJO_CONFIG};
Expand Down Expand Up @@ -176,7 +175,7 @@ Parse configuration file.
=head2 C<register>
my $config = $plugin->register;
my $config = $plugin->register($app, $conf);
Register plugin in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -290,7 +290,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app);
Register helpers in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/EPLRenderer.pm
Expand Up @@ -104,7 +104,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app);
Register renderer in L<Mojolicious> application.
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -9,7 +9,6 @@ use Mojo::Util qw/encode md5_sum/;
# Wishful thinking. We have long since evolved beyond the need for asses."
sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# Custom sandbox
my $template = $conf->{template} || {};
Expand Down Expand Up @@ -129,7 +128,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app, $conf);
Register renderer in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/HeaderCondition.pm
Expand Up @@ -82,7 +82,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app);
Register condition in L<Mojolicious> application.
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Plugin/I18N.pm
Expand Up @@ -8,7 +8,6 @@ use I18N::LangTags::Detect;
# No, the cat shelter’s onto me."
sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# Initialize
my $namespace = $conf->{namespace} || ((ref $app) . "::I18N");
Expand Down Expand Up @@ -165,7 +164,7 @@ and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app, $conf);
Register plugin hooks and helpers in L<Mojolicious> application.
Expand Down
22 changes: 5 additions & 17 deletions lib/Mojolicious/Plugin/JSONConfig.pm
Expand Up @@ -23,26 +23,14 @@ sub parse {
return $config;
}

sub register {
my ($self, $app, $conf) = @_;
$conf->{ext} = 'json' unless exists $conf->{ext};
$self->SUPER::register($app, $conf);
}
sub register { shift->SUPER::register(shift, {ext => 'json', %{shift()}}) }

sub render {
my ($self, $content, $file, $conf, $app) = @_;

# Instance
my $prepend = 'my $app = shift;';

# Be less strict
$prepend .= q/no strict 'refs'; no warnings 'redefine';/;

# Helper
$prepend .= "sub app; *app = sub { \$app };";

# Be strict again
$prepend .= q/use Mojo::Base -strict;/;
# Application instance and helper
my $prepend = q/my $app = shift; no strict 'refs'; no warnings 'redefine';/;
$prepend .= q/sub app; *app = sub { $app }; use Mojo::Base -strict;/;

# Render
my $mt = Mojo::Template->new($conf->{template} || {});
Expand Down Expand Up @@ -118,7 +106,7 @@ Process content with C<render> and parse it with L<Mojo::JSON>.
=head2 C<register>
my $config = $plugin->register;
my $config = $plugin->register($app, $conf);
Register plugin in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/Mount.pm
Expand Up @@ -64,7 +64,7 @@ and implements the following new ones.
=head2 C<register>
my $route = $plugin->register;
my $route = $plugin->register($app, $conf);
Mount L<Mojolicious> application.
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Expand Up @@ -18,7 +18,6 @@ my $PERLDOC = $Mojolicious::Controller::H->slurp_rel_file('perldoc.html.ep');
# pleasant one."
sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# Add "pod" handler
my $preprocess = $conf->{preprocess} || 'ep';
Expand Down Expand Up @@ -206,7 +205,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
my $route = $plugin->register;
my $route = $plugin->register($app, $conf);
Register renderer in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/PoweredBy.pm
Expand Up @@ -54,7 +54,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app, $conf);
Register plugin hooks in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/RequestTimer.pm
Expand Up @@ -72,7 +72,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app);
Register plugin hooks in L<Mojolicious> application.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Plugin/TagHelpers.pm
Expand Up @@ -601,7 +601,7 @@ L<Mojolicious::Plugin> and implements the following new ones.
=head2 C<register>
$plugin->register;
$plugin->register($app);
Register helpers in L<Mojolicious> application.
Expand Down

0 comments on commit c273e15

Please sign in to comment.