Skip to content

Commit

Permalink
added base class without require support to Mojo::Base
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 2, 2012
1 parent 971b327 commit 7707cd8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@
This file documents the revision history for Perl extension Mojolicious.

2.71 2012-04-02
- Added base class without require support to Mojo::Base.
- Improved Hypnotoad error handling.
- Improved version command to detect proxy servers automatically.
- Improved documentation.
Expand Down
13 changes: 11 additions & 2 deletions lib/Mojo/Base.pm
Expand Up @@ -29,7 +29,7 @@ sub import {
else {
my $file = $flag;
$file =~ s/::|'/\//g;
require "$file.pm" unless $flag->can('new');
require "$file.pm" unless $flag =~ s/^\+//;
}

# ISA
Expand Down Expand Up @@ -142,9 +142,10 @@ L<Mojo::Base> is a simple base class for L<Mojo> projects.
# Automatically enables "strict", "warnings" and Perl 5.10 features
use Mojo::Base -strict;
use Mojo::Base -base;
use Mojo::Base '+SomeBaseClass';
use Mojo::Base 'SomeBaseClass';
All three forms save a lot of typing.
All four forms save a lot of typing.
# use Mojo::Base -strict;
use strict;
Expand All @@ -159,6 +160,14 @@ All three forms save a lot of typing.
push @ISA, 'Mojo::Base';
sub has { Mojo::Base::attr(__PACKAGE__, @_) }
# use Mojo::Base '+SomeBaseClass';
use strict;
use warnings;
use feature ':5.10';
push @ISA, 'SomeBaseClass';
use Mojo::Base;
sub has { Mojo::Base::attr(__PACKAGE__, @_) }
# use Mojo::Base 'SomeBaseClass';
use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -742,7 +742,7 @@ support in your application is the plugin L<Mojolicious::Plugin::I18N> and a
few lexicon classes.

package MyApp::I18N::de;
use base 'MyApp::I18N';
use Mojo::Base '+MyApp::I18N';

our %Lexicon = ('Hello World' => 'Hallo Welt');

Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Plugin/I18N.pm
Expand Up @@ -13,10 +13,10 @@ sub register {
# Initialize
my $namespace = $conf->{namespace} || ((ref $app) . "::I18N");
my $default = $conf->{default} || 'en';
eval "package $namespace; use base 'Locale::Maketext'; 1;";
eval "package $namespace; use Mojo::Base 'Locale::Maketext'; 1;";
eval "require ${namespace}::${default};";
unless (eval "\%${namespace}::${default}::Lexicon") {
eval "package ${namespace}::$default; use base '$namespace';"
eval "package ${namespace}::$default; use Mojo::Base '+$namespace';"
. 'our %Lexicon = (_AUTO => 1); 1;';
die qq/Couldn't initialize I18N class "$namespace": $@/ if $@;
}
Expand Down Expand Up @@ -112,9 +112,9 @@ code by default.
# $self->plugin('I18N');
package MyApp::I18N;
use base 'Locale::Maketext';
use Mojo::Base 'Locale::Maketext';
package MyApp::I18N::en;
use base 'MyApp::I18N';
use Mojo::Base '+MyApp::I18N';
our %Lexicon = (_AUTO => 1);
1;
Expand Down
5 changes: 4 additions & 1 deletion t/mojo/base.t
Expand Up @@ -17,6 +17,9 @@ use base 'BaseTest::Base2';
__PACKAGE__->attr(heads => 1);
__PACKAGE__->attr('name');

package BaseTestTest;
use Mojo::Base '+BaseTest';

package main;

use Mojo::Base;
Expand All @@ -32,7 +35,7 @@ for my $i (1 .. 50) {
is $monkeys->[$i]->bananas, $i, 'right attribute value';
}
for my $i (51 .. 100) {
$monkeys->[$i] = BaseTest->new(bananas => $i);
$monkeys->[$i] = BaseTestTest->new(bananas => $i);
is $monkeys->[$i]->bananas, $i, 'right attribute value';
}

Expand Down
3 changes: 1 addition & 2 deletions t/mojolicious/i18n_lite_app.t
Expand Up @@ -9,8 +9,7 @@ BEGIN {
use Test::More tests => 24;

package MyTestApp::I18N::de;
use Mojo::Base -strict;
use base 'MyTestApp::I18N';
use Mojo::Base '+MyTestApp::I18N';

our %Lexicon = (hello => 'hallo');

Expand Down
6 changes: 2 additions & 4 deletions t/mojolicious/i18n_shortcut_lite_app.t
Expand Up @@ -9,14 +9,12 @@ BEGIN {
use Test::More tests => 24;

package MyTestApp::I18N::en;
use Mojo::Base -strict;
use base 'MyTestApp::I18N';
use Mojo::Base '+MyTestApp::I18N';

our %Lexicon = (hello => 'Hello World');

package MyTestApp::I18N::de;
use Mojo::Base -strict;
use base 'MyTestApp::I18N';
use Mojo::Base '+MyTestApp::I18N';

our %Lexicon = (hello => 'Hallo Welt');

Expand Down

0 comments on commit 7707cd8

Please sign in to comment.