Changeset 10255
- Timestamp:
- 04/24/08 10:29:38 (5 years ago)
- Location:
- lang/perl/Sledge-Factory/trunk
- Files:
-
- 4 modified
-
lib/Sledge/Factory.pm (modified) (2 diffs)
-
lib/Sledge/Plugin/Factory.pm (modified) (3 diffs)
-
t/01_foo.t (modified) (1 diff)
-
t/02_cached.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Sledge-Factory/trunk/lib/Sledge/Factory.pm
r10252 r10255 40 40 =head1 NAME 41 41 42 Sledge::Factory - the adaptor.42 Sledge::Factory - the factory. 43 43 44 44 =head1 SYNOPSIS … … 60 60 =head1 DESCRIPTION 61 61 62 Sledge::Factory is adaptormodule for Sledge.62 Sledge::Factory is factory module for Sledge. 63 63 64 64 This is inspire of L<Catalyst::Model::Adaptor> -
lang/perl/Sledge-Factory/trunk/lib/Sledge/Plugin/Factory.pm
r10252 r10255 3 3 use warnings; 4 4 use base qw/Exporter/; 5 our @EXPORT = qw/ adaptor/;5 our @EXPORT = qw/factory/; 6 6 use Sledge::Utils; 7 7 use UNIVERSAL::require; 8 8 9 sub adaptor{9 sub factory { 10 10 my ($app, $module) = @_; 11 11 12 12 my $base = Sledge::Utils::class2appclass($app); 13 my $ adaptor= "${base}::Factory::${module}";14 $ adaptor->require or die $@;13 my $factory = "${base}::Factory::${module}"; 14 $factory->require or die $@; 15 15 16 if ($ adaptor->__per_context) {17 $app->{"__Factory::$module"} ||= _create_instance( $app, $module, $ adaptor);16 if ($factory->__per_context) { 17 $app->{"__Factory::$module"} ||= _create_instance( $app, $module, $factory ); 18 18 } else { 19 _create_instance( $app, $module, $ adaptor);19 _create_instance( $app, $module, $factory ); 20 20 } 21 21 } 22 22 23 23 sub _create_instance { 24 my ($app, $module, $ adaptor) = @_;24 my ($app, $module, $factory) = @_; 25 25 26 26 my $config = $app->create_config->{"Factory::$module"}; 27 27 28 my $constructor = $ adaptor->__constructor;29 my $klass = $ adaptor->__class;28 my $constructor = $factory->__constructor; 29 my $klass = $factory->__class; 30 30 $klass->require or die $@; 31 $klass->$constructor( $ adaptor->__prepare_arguments->($app, $config) );31 $klass->$constructor( $factory->__prepare_arguments->($app, $config) ); 32 32 } 33 33 … … 37 37 =head1 NAME 38 38 39 Sledge::Plugin::Factory - adaptor39 Sledge::Plugin::Factory - factory 40 40 41 41 =head1 SYNOPSIS … … 46 46 sub dispatch_index { 47 47 my $self = shift; 48 $self-> adaptor('TheSchwartz')->insert($job);49 $self-> adaptor('TheSchwartz')->list_jobs({funcname => 'MyApp::Worker'});48 $self->factory('TheSchwartz')->insert($job); 49 $self->factory('TheSchwartz')->list_jobs({funcname => 'MyApp::Worker'}); 50 50 } 51 51 -
lang/perl/Sledge-Factory/trunk/t/01_foo.t
r10248 r10255 10 10 sub dispatch_foo { 11 11 my $self = shift; 12 $self-> adaptor('POPO')->foo;12 $self->factory('POPO')->foo; 13 13 } 14 14 -
lang/perl/Sledge-Factory/trunk/t/02_cached.t
r10248 r10255 10 10 sub dispatch_foo { 11 11 my $self = shift; 12 is $self-> adaptor('POPO')->bar, 1;13 is $self-> adaptor('POPO')->bar, 2;12 is $self->factory('POPO')->bar, 1; 13 is $self->factory('POPO')->bar, 2; 14 14 15 is $self-> adaptor('POPOCached')->bar, 3;16 is $self-> adaptor('POPOCached')->bar, 3; # not incremented here.15 is $self->factory('POPOCached')->bar, 3; 16 is $self->factory('POPOCached')->bar, 3; # not incremented here. 17 17 } 18 18
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)