Skip to content

Instantly share code, notes, and snippets.

@Akron
Created May 19, 2011 16:46
Show Gist options
  • Save Akron/981206 to your computer and use it in GitHub Desktop.
Save Akron/981206 to your computer and use it in GitHub Desktop.
Unexpected behaviour when reregistering plugins
#!/usr/bin/perl
use Mojolicious::Lite;
plugin 'wordlist';
app->words('banana');
plugin 'wordlist';
app->words('apple');
app->words('cherry');
app->start;
package Mojolicious::Plugin::Wordlist;
use Mojo::Base 'Mojolicious::Plugin';
sub register {
my ($plugin, $mojo) = @_;
$plugin->{text} = "Wordlist:\n";
$mojo->helper(
'words' => sub {
return $plugin->add(@_);
}
);
$mojo->routes->route('/')->to(
cb => sub {
shift->render_text($plugin->{text});
}
);
};
sub add {
my ($plugin, $c, $word) = @_;
$plugin->{text} .= $word."\n";
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment