Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Adams committed Apr 24, 2017
0 parents commit ec0bb18
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~$
*.bak
*.old
*.swp
/local
6 changes: 6 additions & 0 deletions .ship.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0.01 Not Released
- Initial release based on kraih's Mojolicious hack of the day: Mojolyst
28 changes: 28 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -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 <stefan@borgia.com>',
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')},
);
5 changes: 5 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requires "perl" => "5.014";
requires "ExtUtils::MakeMaker" => "6.00";
requires "Mojolicious" => "7.11";

test_requires "Test::More" => "0.90";
72 changes: 72 additions & 0 deletions lib/Mojolicious/Plugin/Mojolyst.pm
Original file line number Diff line number Diff line change
@@ -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<Mojolicious::Plugin::Mojolyst> is a L<Mojolicious> plugin to hijack the
Mojolicious router and turn it into a more Catalyst-ish decentralized one.
=head1 METHODS
L<Mojolicious::Plugin::Mojolyst> inherits all methods from
L<Mojolicious::Plugin> and implements the following new ones.
=head2 register
$plugin->register(Mojolicious->new);
Register plugin in L<Mojolicious> application.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>,
L<http://blog.mojolicious.org/post/157278582436/mojolicious-hack-of-the-day-mojolyst>.
=cut
18 changes: 18 additions & 0 deletions t/basic.t
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ec0bb18

Please sign in to comment.