diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eab6ee7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +~$ +*.bak +*.old +*.swp +/local diff --git a/.ship.conf b/.ship.conf new file mode 100644 index 0000000..a2a71ff --- /dev/null +++ b/.ship.conf @@ -0,0 +1,6 @@ +class = App::git::ship::perl +project_name = +homepage = https://github.com/s1037989/Mojolicious-Plugin-Mojolyst +bugtracker = https://github.com/s1037989/Mojolicious-Plugin-Mojolyst/issues +license = artistic_2 +build_test_options = # Example: -l -j8 diff --git a/Changes b/Changes new file mode 100644 index 0000000..86e87fd --- /dev/null +++ b/Changes @@ -0,0 +1,2 @@ +0.01 Not Released + - Initial release based on kraih's Mojolicious hack of the day: Mojolyst diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..2e5b197 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,28 @@ +# Generated by git-ship. See 'git-ship --man' for help or https://github.com/jhthorsen/app-git-ship +use ExtUtils::MakeMaker; +WriteMakefile( + NAME => 'Mojolicious::Plugin::Mojolyst', + AUTHOR => 'Stefan Adams ', + LICENSE => 'artistic_2', + ABSTRACT_FROM => 'lib/Mojolicious/Plugin/Mojolyst.pm', + VERSION_FROM => 'lib/Mojolicious/Plugin/Mojolyst.pm', + EXE_FILES => [qw( )], + META_MERGE => { + resources => { + bugtracker => 'https://github.com/s1037989/Mojolicious-Plugin-Mojolyst/issues', + homepage => 'https://github.com/s1037989/Mojolicious-Plugin-Mojolyst', + repository => 'https://github.com/stefan/mojolicious-plugin-mojolyst', + }, + }, + BUILD_REQUIRES => { + 'Test::More' => '0.90' +} +, + PREREQ_PM => { + 'ExtUtils::MakeMaker' => '6.00', + 'Mojolicious' => '7.11', + 'perl' => '5.014' +} +, + test => {TESTS => (-e 'META.yml' ? 't/*.t' : 't/*.t xt/*.t')}, +); diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..8a295b9 --- /dev/null +++ b/cpanfile @@ -0,0 +1,5 @@ +requires "perl" => "5.014"; +requires "ExtUtils::MakeMaker" => "6.00"; +requires "Mojolicious" => "7.11"; + +test_requires "Test::More" => "0.90"; diff --git a/lib/Mojolicious/Plugin/Mojolyst.pm b/lib/Mojolicious/Plugin/Mojolyst.pm new file mode 100644 index 0000000..ef7fe24 --- /dev/null +++ b/lib/Mojolicious/Plugin/Mojolyst.pm @@ -0,0 +1,72 @@ +package Mojolicious::Plugin::Mojolyst; +use Mojo::Base 'Mojolicious::Plugin'; + +our $VERSION = '0.01'; + +use Mojo::Loader qw/find_modules load_class/; + +sub register { + my ($self, $app, $conf) = @_; + + # Discover controllers + for my $class ( find_modules $conf->{controllers} ) { + + # Steal children + my $e = load_class $class; + my @children = @{$class->new->routes->children}; + $app->routes->add_child($_) for @children; + + # Make DATA sections accessible + push @{$app->static->classes}, $class; + push @{$app->renderer->classes}, $class; + } +} + +1; +__END__ + +=encoding utf8 + +=head1 NAME + +Mojolicious::Plugin::Mojolyst - Mojolicious::Lite syntax in a full Mojolicious +app. + +=head1 SYNOPSIS + + # Mojolicious + $self->plugin('Mojolyst' => {controllers => 'MyApp::Controller'}); + + # Mojolicious::Lite + plugin 'Mojolyst' => {controllers => 'MyApp::Controller'}; + + # In your MyApp::Controller controller + package MyApp::Controller::Foo; + use Mojolicious::Lite; + + get '/' => {text => 'Welcome to Mojolyst!'}; + + 1; + +=head1 DESCRIPTION + +L is a L plugin to hijack the +Mojolicious router and turn it into a more Catalyst-ish decentralized one. + +=head1 METHODS + +L inherits all methods from +L and implements the following new ones. + +=head2 register + + $plugin->register(Mojolicious->new); + +Register plugin in L application. + +=head1 SEE ALSO + +L, L, L, +L. + +=cut diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..fc1cd83 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,18 @@ +package MyApp::Controller::Foo; +use Mojolicious::Lite; + +get '/' => {text => 'Welcome to Mojolyst!'}; + +package main; +use Mojo::Base -strict; + +use Test::More; +use Mojolicious::Lite; +use Test::Mojo; + +plugin 'Mojolyst' => {controllers => 'MyApp::Controller'}; + +my $t = Test::Mojo->new; +$t->get_ok('/')->status_is(200)->content_is('Welcome to Mojolyst!'); + +done_testing();