Created
May 19, 2011 16:46
-
-
Save Akron/981206 to your computer and use it in GitHub Desktop.
Unexpected behaviour when reregistering plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Mojolicious::Lite; | |
plugin 'wordlist'; | |
app->words('banana'); | |
plugin 'wordlist'; | |
app->words('apple'); | |
app->words('cherry'); | |
app->start; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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