[Catalyst-commits] r10560 - in
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst: Model/DBIC
Model/DBIC/Schema TraitFor/Model/DBIC/Schema
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Jun 17 02:26:47 GMT 2009
Author: caelum
Date: 2009-06-17 02:26:47 +0000 (Wed, 17 Jun 2009)
New Revision: 10560
Modified:
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Types.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Caching.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Replicated.pm
Log:
cleanup types, add more attributes to replicated trait
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Types.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Types.pm 2009-06-16 23:16:49 UTC (rev 10559)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Types.pm 2009-06-17 02:26:47 UTC (rev 10560)
@@ -2,8 +2,7 @@
Catalyst::Model::DBIC::Schema::Types;
use MooseX::Types -declare => [qw/
- ConnectInfo ConnectInfos Replicants SchemaClass CursorClass
- CreateOption
+ ConnectInfo ConnectInfos Replicants LoadedClass CreateOption
/];
use Carp::Clan '^Catalyst::Model::DBIC::Schema';
@@ -15,20 +14,13 @@
class_type 'DBIx::Class::Schema';
-subtype SchemaClass,
+subtype LoadedClass,
as ClassName;
-coerce SchemaClass,
+coerce LoadedClass,
from Str,
via { Class::MOP::load_class($_); $_ };
-subtype CursorClass,
- as ClassName;
-
-coerce CursorClass,
- from Str,
- via { Class::MOP::load_class($_); $_ };
-
subtype ConnectInfo,
as HashRef,
where { exists $_->{dsn} },
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm 2009-06-16 23:16:49 UTC (rev 10559)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm 2009-06-17 02:26:47 UTC (rev 10560)
@@ -14,7 +14,7 @@
use Moose::Autobox;
use Catalyst::Model::DBIC::Schema::Types
- qw/ConnectInfo SchemaClass CursorClass/;
+ qw/ConnectInfo LoadedClass/;
use MooseX::Types::Moose qw/ArrayRef Str ClassName Undef/;
@@ -435,7 +435,7 @@
has schema_class => (
is => 'ro',
- isa => SchemaClass,
+ isa => LoadedClass,
coerce => 1,
required => 1
);
@@ -453,7 +453,7 @@
has _default_cursor_class => (
is => 'ro',
- isa => CursorClass,
+ isa => LoadedClass,
default => 'DBIx::Class::Storage::DBI::Cursor',
coerce => 1
);
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Caching.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Caching.pm 2009-06-16 23:16:49 UTC (rev 10559)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Caching.pm 2009-06-17 02:26:47 UTC (rev 10560)
@@ -3,8 +3,7 @@
use namespace::autoclean;
use Moose::Role;
use Carp::Clan '^Catalyst::Model::DBIC::Schema';
-use Catalyst::Model::DBIC::Schema::Types 'CursorClass';
-use MooseX::Types::Moose qw/Int Str/;
+use MooseX::Types::Moose 'Int';
=head1 NAME
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Replicated.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Replicated.pm 2009-06-16 23:16:49 UTC (rev 10559)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/TraitFor/Model/DBIC/Schema/Replicated.pm 2009-06-17 02:26:47 UTC (rev 10560)
@@ -5,7 +5,8 @@
use Moose::Autobox;
use Carp::Clan '^Catalyst::Model::DBIC::Schema';
-use Catalyst::Model::DBIC::Schema::Types 'ConnectInfos';
+use Catalyst::Model::DBIC::Schema::Types qw/ConnectInfos LoadedClass/;
+use MooseX::Types::Moose qw/Str HashRef/;
=head1 NAME
@@ -16,7 +17,7 @@
__PACKAGE__->config({
traits => ['Replicated']
- connect_info =>
+ connect_info =>
['dbi:mysql:master', 'user', 'pass'],
replicants => [
['dbi:mysql:slave1', 'user', 'pass'],
@@ -48,12 +49,37 @@
Array of connect_info settings for every replicant.
+The following can be set via L<Catalyst::Model::DBIC::Schema/connect_info>, or
+as their own parameters. If set via separate parameters, they will override the
+settings in C<connect_info>.
+
+=head2 pool_type
+
+See L<DBIx::Class::Storage::DBI::Replicated/pool_type>.
+
+=head2 pool_args
+
+See L<DBIx::Class::Storage::DBI::Replicated/pool_args>.
+
+=head2 balancer_type
+
+See L<DBIx::Class::Storage::DBI::Replicated/balancer_type>.
+
+=head2 balancer_args
+
+See L<DBIx::Class::Storage::DBI::Replicated/balancer_args>.
+
=cut
has replicants => (
is => 'ro', isa => ConnectInfos, coerce => 1, required => 1
);
+has pool_type => (is => 'ro', isa => LoadedClass);
+has pool_args => (is => 'ro', isa => HashRef);
+has balancer_type => (is => 'ro', isa => Str);
+has balancer_args => (is => 'ro', isa => HashRef);
+
after setup => sub {
my $self = shift;
@@ -69,16 +95,26 @@
$self->storage_type('::DBI::Replicated');
}
- $self->connect_info->{balancer_type} ||= '::Random'
- unless $self->connect_info->{balancer_type};
+ my $connect_info = $self->connect_info;
- unless ($self->connect_info->{balancer_args} &&
- exists $self->connect_info->{balancer_args}{master_read_weight}) {
- $self->connect_info->{balancer_args}{master_read_weight} = 1;
- }
+ $connect_info->{pool_type} = $self->pool_type
+ if $self->pool_type;
+
+ $connect_info->{pool_args} = $self->pool_args
+ if $self->pool_args;
+
+ $connect_info->{balancer_type} = $self->balancer_type ||
+ $connect_info->{balancer_type} || '::Random';
+
+ $connect_info->{balancer_args} = $self->balancer_args ||
+ $connect_info->{balancer_args} || {};
+
+ $connect_info->{balancer_args}{master_read_weight} = 1
+ unless exists $connect_info->{balancer_args}{master_read_weight};
};
sub BUILD {}
+
after BUILD => sub {
my $self = shift;
More information about the Catalyst-commits
mailing list