Skip to content

Commit

Permalink
fixed small name generation bug in Mojolicious::Plugin::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 13, 2011
1 parent 62057f8 commit 5ed131f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 14 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -12,6 +12,7 @@ This file documents the revision history for Perl extension Mojolicious.
(viliampucik)
- Improved non-blocking resolver by allowing it to be disabled.
- Improved tests.
- Fixed small name generation bug in Mojolicious::Plugin::Config.
- Fixed small bug in cookie jar.
- Fixed small plugin loader bug.
- Fixed Hypnotoad to clean up lock files.
Expand Down
19 changes: 12 additions & 7 deletions lib/Mojolicious/Plugin/Config.pm
@@ -1,8 +1,9 @@
package Mojolicious::Plugin::Config;
use Mojo::Base 'Mojolicious::Plugin';

require File::Basename;
require File::Spec;
use File::Basename 'basename';
use File::Spec;
use Mojo::Util 'decamelize';

use constant DEBUG => $ENV{MOJO_CONFIG_DEBUG} || 0;

Expand Down Expand Up @@ -37,15 +38,19 @@ sub register {
my ($self, $app, $conf) = @_;
$conf ||= {};

# File
# Config file
my $file = $conf->{file} || $ENV{MOJO_CONFIG};
unless ($file) {
$file = $ENV{MOJO_APP};

# Basename
$file = File::Basename::basename($ENV{MOJO_EXE} || $0);
# Class
if ($file && !ref $file) { decamelize $file }

# Remove .pl, .p6 and .t extentions
$file =~ s/(?:\.p(?:l|6))|\.t$//i;
# File
else { $file = basename($ENV{MOJO_EXE} || $0) }

# Remove .pl and .t extentions
$file =~ s/\.(?:pl|t)$//i;

# Default extension
$file .= '.' . ($conf->{ext} || 'conf');
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Renderer.pm
Expand Up @@ -230,8 +230,6 @@ sub _list_data_templates {
return [keys %$all];
}

# "Well, at least here you'll be treated with dignity.
# Now strip naked and get on the probulator."
sub _render_template {
my ($self, $c, $output, $options) = @_;

Expand Down
7 changes: 4 additions & 3 deletions lib/Test/Mojo.pm
Expand Up @@ -37,9 +37,10 @@ EOF
}

sub app {
my $self = shift;
return $self->ua->app unless @_;
$self->ua->app(@_);
my ($self, $app) = @_;
return $self->ua->app unless $app;
$ENV{MOJO_APP} ||= $app;
$self->ua->app($app);
return $self;
}

Expand Down
30 changes: 30 additions & 0 deletions t/mojolicious/external/lib/MyApp.pm
@@ -0,0 +1,30 @@
package MyApp;
use Mojo::Base 'Mojolicious';

# "Well, at least here you'll be treated with dignity.
# Now strip naked and get on the probulator."
sub startup {
my $self = shift;
my $r = $self->routes;

# Load plugin
$self->plugin('Config');

# GET /
$r->get(
'/' => sub {
my $self = shift;
$self->render(text => $self->config->{works});
}
);

# GET /test
$r->get(
'/test' => sub {
my $self = shift;
$self->render(text => $self->config->{whatever});
}
);
}

1;
1 change: 1 addition & 0 deletions t/mojolicious/external/my_app.conf
@@ -0,0 +1 @@
{works => 'too!'}
1 change: 1 addition & 0 deletions t/mojolicious/external/my_app.testing.conf
@@ -0,0 +1 @@
{whatever => 'works!'};
30 changes: 30 additions & 0 deletions t/mojolicious/external_app.t
@@ -0,0 +1,30 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use utf8;

# Disable Bonjour, IPv6 and libev
BEGIN {
$ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1;
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
$ENV{MOJO_MODE} = 'testing';
}

# "Of all the parasites I've had over the years,
# these worms are among the best."
use Test::More tests => 9;
use Test::Mojo;

use FindBin;
use lib "$FindBin::Bin/external/lib";
my $t = Test::Mojo->new('MyApp');

# GET /
$t->get_ok('/')->status_is(200)->content_is('too!');

# GET /index.html
$t->get_ok('/index.html')->status_is(200)
->content_is('External static file!');

# GET /test
$t->get_ok('/test')->status_is(200)->content_is('works!');
2 changes: 0 additions & 2 deletions t/mojolicious/external_lite_app.t
Expand Up @@ -13,8 +13,6 @@ BEGIN {
# "Who are you, and why should I care?"
use Test::More tests => 15;

# "Of all the parasites I've had over the years,
# these worms are among the best."
use FindBin;
require "$FindBin::Bin/external/myapp.pl";
use Test::Mojo;
Expand Down

0 comments on commit 5ed131f

Please sign in to comment.