Skip to content

Commit

Permalink
use Moose to extend class in BEGIN
Browse files Browse the repository at this point in the history
  • Loading branch information
dann committed May 16, 2008
1 parent f4cb407 commit ea0cf12
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 19 deletions.
10 changes: 7 additions & 3 deletions examples/simple_model.pl
Expand Up @@ -3,15 +3,19 @@
use lib 'lib';

{

package MyApp::Model::Simple;
use Moose;
use base 'Paffy::Model';

sub businessLogic: Before(Debug) {
BEGIN {
extends 'Paffy::Model';
}

sub businessLogic : Before(Debug) {
my ($self) = shift;
print 'Hello';
}
}

my $model =MyApp::Model::Simple->new;
my $model = MyApp::Model::Simple->new;
$model->businessLogic();
5 changes: 4 additions & 1 deletion lib/Paffy/CLI.pm
@@ -1,6 +1,9 @@
package Paffy::CLI;
use Moose;
extends qw(MooseX::App::Cmd);

BEGIN {
extends qw(MooseX::App::Cmd);
}

no Moose;

Expand Down
4 changes: 3 additions & 1 deletion lib/Paffy/CLI/Command.pm
@@ -1,6 +1,8 @@
package Paffy::CLI::Command;
use Moose;
extends qw(MooseX::App::Cmd::Command);
BEGIN {
extends qw(MooseX::App::Cmd::Command);
}

has 'config' => (
is => 'rw',
Expand Down
4 changes: 3 additions & 1 deletion lib/Paffy/CLI/Command/example.pm
@@ -1,6 +1,8 @@
package Paffy::CLI::Command::example;
use Moose;
extends qw(Paffy::CLI::Command);
BEGIN {
extends qw(Paffy::CLI::Command);
}

has open => (
isa => "Str",
Expand Down
1 change: 0 additions & 1 deletion lib/Paffy/Cache.pm
@@ -1,5 +1,4 @@
package Paffy::Cache;
use CHI;
use Moose;

has 'cache' => (
Expand Down
6 changes: 4 additions & 2 deletions lib/Paffy/Class.pm
@@ -1,11 +1,13 @@
package Paffy::Class;
use attributes();
use Moose;
use base qw/Paffy::Component Paffy::AttrContainer/;
BEGIN {
extends qw(Paffy::Component Paffy::AttrContainer);
}

no Moose;

__PACKAGE__->meta->make_immutable();
__PACKAGE__->meta->make_immutable;

1;

Expand Down
7 changes: 5 additions & 2 deletions lib/Paffy/Model.pm
@@ -1,9 +1,12 @@
package Paffy::Model;
use Moose;
use base qw/Paffy::Class/;

BEGIN {
extends qw(Paffy::Class);
}

no Moose;
__PACKAGE__->meta->make_immutable();
__PACKAGE__->meta->make_immutable;

1;

Expand Down
14 changes: 10 additions & 4 deletions lib/Paffy/Model/DBIC.pm
@@ -1,19 +1,23 @@
package Paffy::Model::DBIC;
use Moose;
extends 'Paffy::Model';
BEGIN {
extends qw(Paffy::Model);
}

has 'schema' => ( is => 'rw' );
has 'slave_schema' => ( is => 'rw' );

sub model {
no Moose;

sub dbic {
my ( $self, $model_name ) = @_;
my $name = $self->_get_resultset_name($model_name);
my $name = $self->_get_resultset_name($model_name);
return $self->schema->resultset($name);
}

sub slave_model {
my ( $self, $model_name ) = @_;
my $name = $self->_get_resultset_name($model_name);
my $name = $self->_get_resultset_name($model_name);
return $self->slave_schema->resultset($name);
}

Expand All @@ -23,6 +27,8 @@ sub _get_resultset_name {
return $name;
}

__PACKAGE__->meta->make_immutable;

1;

__END__
4 changes: 3 additions & 1 deletion lib/Paffy/Model/JobQueue.pm
@@ -1,5 +1,7 @@
package Paffy::Model::JobQueue;
use Moose;
extends 'Paffy::Class';
BEGIN {
extends qw(Paffy::Model);
}

1;
2 changes: 1 addition & 1 deletion lib/Paffy/ORM/DBIx/Class/Storage/DBI/Cached.pm
@@ -1,6 +1,6 @@
package Paffy::ORM::DBIx::Class::Storage::DBI::Cached;
use strict;
use base qw(DBIx::Class::Storage::DBI);
use base qw(DBIx::Class::Storage::DBI Class::Accessor::Fast);
our $CACHE_EXPIRE = 60 * 60;

# set cache before use this class
Expand Down
6 changes: 4 additions & 2 deletions lib/Paffy/Service.pm
@@ -1,7 +1,9 @@
package Paffy::Service;

use Moose;
use base qw/Paffy::Model/;

BEGIN {
extends qw(Paffy::Model);
}

1;

Expand Down

0 comments on commit ea0cf12

Please sign in to comment.