[Catalyst-commits] r10283 - in trunk/Catalyst-Model-DBIC-Schema:
lib/Catalyst/Helper/Model/DBIC lib/Catalyst/Model/DBIC
lib/Catalyst/Model/DBIC/Schema
lib/Catalyst/Model/DBIC/Schema/Trait t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Tue May 26 01:04:35 GMT 2009
Author: caelum
Date: 2009-05-26 01:04:34 +0000 (Tue, 26 May 2009)
New Revision: 10283
Added:
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/
Removed:
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Role/
Modified:
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Caching.pm
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Replicated.pm
trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t
trunk/Catalyst-Model-DBIC-Schema/t/08helper.t
Log:
2 char quote_char support and s/roles/traits/
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm 2009-05-25 22:51:03 UTC (rev 10282)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm 2009-05-26 01:04:34 UTC (rev 10283)
@@ -24,7 +24,7 @@
=head1 SYNOPSIS
script/create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass \
- [ create=dynamic | create=static ] [ roles=role1,role2... ] \
+ [ create=dynamic | create=static ] [ traits=trait1,trait2... ] \
[ Schema::Loader opts ] [ dsn user pass ] \
[ other connect_info args ]
@@ -56,7 +56,7 @@
adapt itself to changes in your database structure. You can edit
the generated classes by hand to refine them.
-C<roles> is the list of roles to apply to the model, see
+C<traits> is the list of traits to apply to the model, see
L<Catalyst::Model::DBIC::Schema> for details.
C<Schema::Loader opts> are described in L</TYPICAL EXAMPLES> below.
@@ -88,6 +88,10 @@
AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
on_connect_do='["select 1", "select 2"]' quote_char='"'
+If using a 2 character quote_char:
+
+ script/myapp_create.pl ... quote_char='[]'
+
B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT>
In C<cmd.exe> the above example would be:
@@ -127,7 +131,7 @@
has helper => (is => 'ro', isa => 'Catalyst::Helper', required => 1);
has create => (is => 'rw', isa => CreateOption);
has args => (is => 'ro', isa => ArrayRef);
-has roles => (is => 'rw', isa => ArrayRef);
+has traits => (is => 'rw', isa => ArrayRef);
has schema_class => (is => 'ro', isa => Str, required => 1);
has loader_args => (is => 'rw', isa => HashRef);
has connect_info => (is => 'rw', isa => HashRef);
@@ -164,17 +168,17 @@
@args = $self->_cleanup_args(\@args);
- my ($roles_idx, $roles);
- if (($roles_idx = firstidx { ($roles) = /^roles=(\S*)\z/ } @args) != -1) {
- my @roles = split /,/ => $roles;
+ my ($traits_idx, $traits);
+ if (($traits_idx = firstidx { ($traits) = /^traits=(\S*)\z/ } @args) != -1) {
+ my @traits = split /,/ => $traits;
- $self->roles(\@roles);
+ $self->traits(\@traits);
- $helper->{roles} = '['
- .(join ',' => map { qq{'$_'} } ($self->roles->flatten))
+ $helper->{traits} = '['
+ .(join ',' => map { qq{'$_'} } ($self->traits->flatten))
.']';
- splice @args, $roles_idx, 1, ();
+ splice @args, $traits_idx, 1, ();
}
if ($args[0] && $args[0] =~ /^create=(\S*)\z/) {
@@ -339,7 +343,7 @@
if (ref $val) {
$val = $self->_data_struct_to_string($val);
} else {
- $val = 'q{'.$val.'}';
+ $val = $self->_quote($val);
}
$helper_connect_info{$key} = $val;
@@ -350,7 +354,13 @@
my ($key, $val) = split /=/, $_, 2;
- $helper_connect_info{$key} = $self->_quote_unless_struct($val);
+ if ($key eq 'quote_char') {
+ $helper_connect_info{$key} = length($val) == 1 ?
+ $self->_quote($val) :
+ $self->_data_struct_to_string([split //, $val]);
+ } else {
+ $helper_connect_info{$key} = $self->_quote_unless_struct($val);
+ }
}
\%helper_connect_info
@@ -421,7 +431,9 @@
my ($key, $val) = split /=/, $_, 2;
- if ($key =~ /^(?:quote_char|name_sep|limit_dialect)\z/) {
+ if ($key eq 'quote_char') {
+ $connect_info{$key} = length($val) == 1 ? $val : [split //, $val];
+ } elsif ($key =~ /^(?:name_sep|limit_dialect)\z/) {
$connect_info{$key} = $val;
} else {
$connect_info{$key} = $self->_eval($val);
@@ -442,12 +454,18 @@
return $val =~ /^\s*[[{]/;
}
+sub _quote {
+ my ($self, $val) = @_;
+
+ return 'q{'.$val.'}';
+}
+
sub _quote_unless_struct {
my ($self, $val) = @_;
- $val = 'q{'.$val.'}' if not $self->_is_struct($val);
+ $val = $self->_quote($val) if not $self->_is_struct($val);
- $val;
+ return $val;
}
sub _eval {
@@ -615,7 +633,7 @@
__PACKAGE__->config(
schema_class => '[% schema_class %]',
- [% IF roles %]roles => [% roles %],[% END %]
+ [% IF traits %]traits => [% traits %],[% END %]
[% IF setup_connect_info %]connect_info => {
[%- FOREACH key = connect_info.keys %]
[% key %] => [% connect_info.${key} %],
Copied: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait (from rev 10280, trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Role)
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Caching.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Role/Caching.pm 2009-05-25 15:52:55 UTC (rev 10280)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Caching.pm 2009-05-26 01:04:34 UTC (rev 10283)
@@ -1,4 +1,4 @@
-package Catalyst::Model::DBIC::Schema::Role::Caching;
+package Catalyst::Model::DBIC::Schema::Trait::Caching;
use Moose::Role;
use Carp::Clan '^Catalyst::Model::DBIC::Schema';
@@ -9,13 +9,13 @@
=head1 NAME
-Catalyst::Model::DBIC::Schema::Role::Caching - Query caching support for
+Catalyst::Model::DBIC::Schema::Trait::Caching - Query caching support for
Catalyst::Model::DBIC::Schema
=head1 SYNOPSIS
__PACKAGE__->config({
- roles => ['Caching'],
+ traits => ['Caching'],
connect_info =>
['dbi:mysql:db', 'user', 'pass'],
});
@@ -52,7 +52,7 @@
=cut
-has 'caching' => (is => 'rw', isa => Int, default => 1);
+has caching => (is => 'rw', isa => Int, default => 1);
after setup => sub {
my $self = shift;
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Replicated.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Role/Replicated.pm 2009-05-25 15:52:55 UTC (rev 10280)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema/Trait/Replicated.pm 2009-05-26 01:04:34 UTC (rev 10283)
@@ -1,4 +1,4 @@
-package Catalyst::Model::DBIC::Schema::Role::Replicated;
+package Catalyst::Model::DBIC::Schema::Trait::Replicated;
use Moose::Role;
use Moose::Autobox;
@@ -10,13 +10,13 @@
=head1 NAME
-Catalyst::Model::DBIC::Schema::Role::Replicated - Replicated storage support for
+Catalyst::Model::DBIC::Schema::Trait::Replicated - Replicated storage support for
L<Catalyst::Model::DBIC::Schema>
=head1 SYNOPSiS
__PACKAGE__->config({
- roles => ['Replicated']
+ traits => ['Replicated']
connect_info =>
['dbi:mysql:master', 'user', 'pass'],
replicants => [
@@ -45,12 +45,12 @@
=head1 NOTE ON L<DBIx::Class> VERSIONS PRIOR TO 0.08103
-This role will work, however, any C<::Storage::Replicated> options in
+This trait will work, however, any C<::Storage::Replicated> options in
L<Catalyst::Model::DBIC::Schema/connect_info> will be ignored, master
connect_info will not be merged to replicants, and
L<DBIx::Class::Storage::DBI::Replicated::Balancer::First> will be used instead,
with all your reads going only to one of your replicants. You'll also get some
-warnings. The C<Caching> role will also not work.
+warnings. The C<Caching> trait will also not work.
Please upgrade.
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm 2009-05-25 22:51:03 UTC (rev 10282)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm 2009-05-26 01:04:34 UTC (rev 10283)
@@ -240,7 +240,7 @@
<Model::FilmDB>
schema_class MyApp::Schema::FilmDB
- roles Caching
+ traits Caching
<connect_info>
dsn dbi:Pg:dbname=mypgdb
user postgres
@@ -292,36 +292,36 @@
}
]
-=head2 roles
+=head2 traits
-Array of Roles to apply at BUILD time. Roles are relative to the
-C<<MyApp::Model::DB::Role::> then C<<Catalyst::Model::DBIC::Schema::Role::>>
+Array of Traits to apply at BUILD time. Traits are relative to the
+C<<MyApp::Model::DB::Trait::> then C<<Catalyst::Model::DBIC::Schema::Trait::>>
namespaces, unless prefixed with C<+> in which case they are taken to be a
fully qualified name. E.g.:
- roles Caching
- roles +MyApp::DB::Role::Foo
+ traits Caching
+ traits +MyApp::DB::Trait::Foo
This is done using L<MooseX::Object::Pluggable>.
A new instance is created at application time, so any consumed required
attributes, coercions and modifiers will work.
-Roles are applied before setup, schema and connection are set.
+Traits are applied before setup, schema and connection are set.
-C<ref $self> will be an anon class if any roles are applied.
+C<ref $self> will be an anon class if any traits are applied.
You cannot modify C<new> or C<BUILD>, modify C<setup> instead.
L</ACCEPT_CONTEXT> and L</finalize> can also be modified.
-Roles that come with the distribution:
+Traits that come with the distribution:
=over 4
-=item L<Catalyst::Model::DBIC::Schema::Role::Caching>
+=item L<Catalyst::Model::DBIC::Schema::Trait::Caching>
-=item L<Catalyst::Model::DBIC::Schema::Role::Replicated>
+=item L<Catalyst::Model::DBIC::Schema::Trait::Replicated>
=back
@@ -381,20 +381,20 @@
=cut
-has 'schema' => (is => 'rw', isa => 'DBIx::Class::Schema');
+has schema => (is => 'rw', isa => 'DBIx::Class::Schema');
-has 'schema_class' => (
+has schema_class => (
is => 'ro',
isa => SchemaClass,
coerce => 1,
required => 1
);
-has 'storage_type' => (is => 'rw', isa => Str);
+has storage_type => (is => 'rw', isa => Str);
-has 'connect_info' => (is => 'ro', isa => ConnectInfo, coerce => 1);
+has connect_info => (is => 'ro', isa => ConnectInfo, coerce => 1);
-has 'model_name' => (is => 'ro', isa => Str, default => sub {
+has model_name => (is => 'ro', isa => Str, default => sub {
my $self = shift;
my $class = ref $self;
@@ -403,9 +403,9 @@
$model_name
});
-has 'roles' => (is => 'ro', isa => ArrayRef|Str);
+has traits => (is => 'ro', isa => ArrayRef|Str);
-has '_default_cursor_class' => (
+has _default_cursor_class => (
is => 'ro',
isa => CursorClass,
default => 'DBIx::Class::Storage::DBI::Cursor',
@@ -435,9 +435,9 @@
. " ".$self->connect_info->{cursor_class}.": $@";
}
- $self->_plugin_ns('Role');
+ $self->_plugin_ns('Trait');
- $self->load_plugins($self->roles->flatten) if $self->roles;
+ $self->load_plugins($self->traits->flatten) if $self->traits;
$self->setup;
@@ -546,10 +546,10 @@
L<DBIx::Class::Schema::Loader>, L<Catalyst::Helper::Model::DBIC::Schema>,
L<MooseX::Object::Pluggable>
-Roles:
+Traits:
-L<Catalyst::Model::DBIC::Schema::Role::Caching>,
-L<Catalyst::Model::DBIC::Schema::Role::Replicated>
+L<Catalyst::Model::DBIC::Schema::Trait::Caching>,
+L<Catalyst::Model::DBIC::Schema::Trait::Replicated>
=head1 AUTHOR
Modified: trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t 2009-05-25 22:51:03 UTC (rev 10282)
+++ trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t 2009-05-26 01:04:34 UTC (rev 10283)
@@ -12,8 +12,8 @@
my $test_params = [
[ 'TestSchema', 'DBIC::Schema', '' ],
[ 'TestSchemaDSN', 'DBIC::Schema', q{fakedsn fakeuser fakepass "{ AutoCommit => 1 }"} ],
- [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static roles=Caching moniker_map="{ roles => \"ROLE\" }" constraint="^users\z" dbi:SQLite:testdb.db "" "" on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
- [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static roles=Caching moniker_map="{ roles => \"ROLE\" }" dbi:SQLite:testdb.db on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
+ [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static traits=Caching moniker_map="{ roles => \"ROLE\" }" constraint="^users\z" dbi:SQLite:testdb.db "" "" on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
+ [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static traits=Caching moniker_map="{ roles => \"ROLE\" }" dbi:SQLite:testdb.db on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
];
plan tests => (2 * @$test_params + 2);
Modified: trunk/Catalyst-Model-DBIC-Schema/t/08helper.t
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/t/08helper.t 2009-05-25 22:51:03 UTC (rev 10282)
+++ trunk/Catalyst-Model-DBIC-Schema/t/08helper.t 2009-05-26 01:04:34 UTC (rev 10283)
@@ -4,7 +4,7 @@
use FindBin '$Bin';
use lib "$Bin/lib";
-use Test::More tests => 38;
+use Test::More tests => 40;
use Test::Exception;
use Catalyst::Helper::Model::DBIC::Schema;
use Catalyst::Helper;
@@ -24,13 +24,13 @@
$i = instance(schema_class => 'ASchemaClass');
is $i->old_schema, 1, '->load_classes detected correctly';
-$i = instance(args => ['roles=Caching']);
-is_deeply $i->roles, ['Caching'], 'one role';
-is $i->helper->{roles}, "['Caching']", 'one role as string';
+$i = instance(args => ['traits=Caching']);
+is_deeply $i->traits, ['Caching'], 'one trait';
+is $i->helper->{traits}, "['Caching']", 'one trait as string';
-$i = instance(args => ['roles=Caching,Replicated']);
-is_deeply $i->roles, ['Caching', 'Replicated'], 'two roles';
-is $i->helper->{roles}, "['Caching','Replicated']", 'two roles as string';
+$i = instance(args => ['traits=Caching,Replicated']);
+is_deeply $i->traits, ['Caching', 'Replicated'], 'two traits';
+is $i->helper->{traits}, "['Caching','Replicated']", 'two traits as string';
$i = instance(args => [$static]);
is $i->create, 'static', 'create=static';
@@ -131,6 +131,15 @@
is $i->connect_info->{password}, 'pass', 'password';
$i = instance(args => [
+ $static, $pg, 'user', 'pass', 'quote_char=[]', $name_sep
+]);
+
+is_deeply $i->connect_info->{quote_char}, ['[', ']'],
+ '2 character quote_char';
+is $i->helper->{connect_info}{quote_char}, '["[","]"]',
+ '2 character quote_char as string';
+
+$i = instance(args => [
$static, 'components=TimeStamp', $sqlite, $on_connect_do,
$quote_char, $name_sep, '{ auto_savepoint => 1, AutoCommit => 0 }'
]);
More information about the Catalyst-commits
mailing list