Cosmetic: Fix attribute lines types and defaults
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Model / DBIC / Schema.pm
CommitLineData
ad91060a 1package Catalyst::Model::DBIC::Schema;
2
0fbbc8d5 3use Moose;
0f3de2c4 4use mro 'c3';
0fbbc8d5 5extends 'Catalyst::Model';
fb691af9 6with 'CatalystX::Component::Traits';
0fbbc8d5 7
2a5644e8 8our $VERSION = '0.65';
7dfd616a 9$VERSION = eval $VERSION;
f090a149 10
73f72d28 11use namespace::autoclean;
bd309c0c 12use Carp::Clan '^Catalyst::Model::DBIC::Schema';
bfcd6e3d 13use Data::Dumper;
2201c2e4 14use DBIx::Class ();
45b10191 15use Module::Runtime qw/use_module/;
ad91060a 16
61ed82a5 17use Catalyst::Model::DBIC::Schema::Types
45b10191 18 qw/ConnectInfo SchemaClass Schema/;
61ed82a5 19
0f64d02c 20use MooseX::Types::Moose qw/Str Bool/;
45b10191 21use MooseX::Types::LoadableClass qw/LoadableClass/;
0fbbc8d5 22
ad91060a 23=head1 NAME
24
25Catalyst::Model::DBIC::Schema - DBIx::Class::Schema Model Class
26
27=head1 SYNOPSIS
28
cbe03ea7 29First, prepare your database schema using L<DBIx::Class>, see
30L<Catalyst::Helper::Model::DBIC::Schema> for how to generate a
31L<DBIx::Class::Schema> from your database using the Helper script, and
32L<DBIx::Class::Schema::Loader::Base>.
07edc53e 33
cbe03ea7 34A typical usage of the helper script would be:
aabc1d75 35
cbe03ea7 36 script/myapp_create.pl model FilmDB DBIC::Schema MyApp::Schema::FilmDB \
37 create=static dbi:mysql:filmdb dbusername dbpass \
f24a5fbb 38 quote_names=1
aabc1d75 39
cbe03ea7 40If you are unfamiliar with L<DBIx::Class>, see L<DBIx::Class::Manual::Intro>
41first.
aabc1d75 42
cbe03ea7 43These examples assume that you already have a schema called
44C<MyApp::Schema::FilmDB>, which defines some Result classes for tables in
45C<MyApp::Schema::FilmDB::Result::Actor> and
46C<MyApp::Schema::FilmDB::Result::Film>. Either created by the helper script (as
47shown above) or manually.
aabc1d75 48
cbe03ea7 49The helper also creates a Model in C<lib/MyApp/Model/FilmDB.pm>, if you already
50have a schema you can create just the Model using:
07edc53e 51
cbe03ea7 52 script/myapp_create.pl model FilmDB DBIC::Schema MyApp::Schema::FilmDB
53 dbi:mysql:filmdb dbusername dbpass
aabc1d75 54
cbe03ea7 55The connect_info is optional and will be hardcoded into the Model if provided.
56It's better to configure it in your L<Catalyst> config file, which will also
57override any hardcoded config, see L</connect_info> for examples.
aabc1d75 58
95b41ca8 59Now you have a working Model which accesses your separate DBIC Schema. This can
60be used/accessed in the normal Catalyst manner, via C<< $c->model() >>:
aabc1d75 61
95b41ca8 62 my $db_model = $c->model('FilmDB'); # a Catalyst::Model
63 my $dbic = $c->model('FilmDB')->schema; # the actual DBIC object
aabc1d75 64
95b41ca8 65There is also a shortcut, which returns a L<DBIx::Class::ResultSet> directly,
66instead of a L<Catalyst::Model>:
07edc53e 67
95b41ca8 68 my $rs = $c->model('FilmDB::Actor');
aabc1d75 69
cbe03ea7 70See L<DBIx::Class::ResultSet> to find out more about which methods can be
71called on ResultSets.
72
73You can also define your own ResultSet methods to encapsulate the
74database/business logic of your applications. These go into, for example,
75C<lib/MyApp/Schema/FilmDB/ResultSet/Actor.pm>. The class must inherit from
76L<DBIx::Class::ResultSet> and is automatically loaded.
77
78Then call your methods like any other L<DBIx::Class::ResultSet> method:
79
80 $c->model('FilmDB::Actor')->SAG_members
aabc1d75 81
95b41ca8 82=head2 Some examples:
aabc1d75 83
f1613faa 84 # to access schema methods directly:
85 $c->model('FilmDB')->schema->source(...);
86
87 # to access the source object, resultset, and class:
07edc53e 88 $c->model('FilmDB')->source(...);
89 $c->model('FilmDB')->resultset(...);
90 $c->model('FilmDB')->class(...);
c12b7310 91
07edc53e 92 # For resultsets, there's an even quicker shortcut:
93 $c->model('FilmDB::Actor')
94 # is the same as $c->model('FilmDB')->resultset('Actor')
ad91060a 95
f1613faa 96 # To get the composed schema for making new connections:
97 my $newconn = $c->model('FilmDB')->composed_schema->connect(...);
98
99 # Or the same thing via a convenience shortcut:
100 my $newconn = $c->model('FilmDB')->connect(...);
101
102 # or, if your schema works on different storage drivers:
103 my $newconn = $c->model('FilmDB')->composed_schema->clone();
104 $newconn->storage_type('::LDAP');
105 $newconn->connection(...);
106
107 # and again, a convenience shortcut
108 my $newconn = $c->model('FilmDB')->clone();
109 $newconn->storage_type('::LDAP');
110 $newconn->connection(...);
111
95b41ca8 112To set up authentication, see L</"Setting up DBIC authentication"> below.
113
ad91060a 114=head1 DESCRIPTION
115
7b39f3f0 116This is a Catalyst Model for L<DBIx::Class::Schema>-based Models. See
ef91bcf9 117the documentation for L<Catalyst::Helper::Model::DBIC::Schema> for
118information on generating these Models via Helper scripts.
ad91060a 119
cbe03ea7 120When your Catalyst app starts up, a thin Model layer is created as an interface
121to your DBIC Schema. It should be clearly noted that the model object returned
122by C<< $c->model('FilmDB') >> is NOT itself a DBIC schema or resultset object,
123but merely a wrapper proving L<methods|/METHODS> to access the underlying
ae3d05c2 124schema.
d52bc376 125
126In addition to this model class, a shortcut class is generated for each
127source in the schema, allowing easy and direct access to a resultset of the
128corresponding type. These generated classes are even thinner than the model
129class, providing no public methods but simply hooking into Catalyst's
130model() accessor via the
131L<ACCEPT_CONTEXT|Catalyst::Component/ACCEPT_CONTEXT> mechanism. The complete
132contents of each generated class is roughly equivalent to the following:
133
134 package MyApp::Model::FilmDB::Actor
135 sub ACCEPT_CONTEXT {
136 my ($self, $c) = @_;
137 $c->model('FilmDB')->resultset('Actor');
138 }
139
140In short, there are three techniques available for obtaining a DBIC
141resultset object:
142
143 # the long way
144 my $rs = $c->model('FilmDB')->schema->resultset('Actor');
145
146 # using the shortcut method on the model object
147 my $rs = $c->model('FilmDB')->resultset('Actor');
148
149 # using the generated class directly
150 my $rs = $c->model('FilmDB::Actor');
151
c082639a 152In order to add methods to a DBIC resultset, you cannot simply add them to
153the source (row, table) definition class; you must define a separate custom
cbe03ea7 154resultset class. This is just a matter of making a
155C<lib/MyApp/Schema/ResultSet/Actor.pm> class that inherits from
156L<DBIx::Class::ResultSet>, if you are using
157L<DBIx::Class::Schema/load_namespaces>, the default for helper script generated
158schemas.
159
160See L<DBIx::Class::Manual::Cookbook/"Predefined searches">
161for information on definining your own L<DBIx::Class::ResultSet> classes for
162use with L<DBIx::Class::Schema/load_classes>, the old default.
c082639a 163
ad91060a 164=head1 CONFIG PARAMETERS
165
c4fee9b8 166=head2 schema_class
ad91060a 167
168This is the classname of your L<DBIx::Class::Schema> Schema. It needs
aabc1d75 169to be findable in C<@INC>, but it does not need to be inside the
170C<Catalyst::Model::> namespace. This parameter is required.
ad91060a 171
c4fee9b8 172=head2 connect_info
ad91060a 173
f24a5fbb 174This is a hashref or arrayref of connection parameters, which are specific to
175your C<storage_type> (see your storage type documentation for more details). If
176you only need one parameter (e.g. the DSN), you can just pass a string.
ad91060a 177
0f2fd2c0 178This is not required if C<schema_class> already has connection information
f24a5fbb 179defined inside itself (which isn't highly recommended, but can be done.)
0f2fd2c0 180
7db6da78 181For L<DBIx::Class::Storage::DBI>, which is the only supported
182C<storage_type> in L<DBIx::Class> at the time of this writing, the
183parameters are your dsn, username, password, and connect options hashref.
184
018eb0e2 185See L<DBIx::Class::Storage::DBI/connect_info> for a detailed explanation
186of the arguments supported.
7db6da78 187
188Examples:
189
2201c2e4 190 connect_info => {
191 dsn => 'dbi:Pg:dbname=mypgdb',
192 user => 'postgres',
193 password => ''
194 }
07edc53e 195
2201c2e4 196 connect_info => {
197 dsn => 'dbi:SQLite:dbname=foo.db',
198 on_connect_do => [
199 'PRAGMA synchronous = OFF',
200 ]
201 }
07edc53e 202
2201c2e4 203 connect_info => {
204 dsn => 'dbi:Pg:dbname=mypgdb',
205 user => 'postgres',
206 password => '',
207 pg_enable_utf8 => 1,
208 on_connect_do => [
209 'some SQL statement',
210 'another SQL statement',
211 ],
212 }
7db6da78 213
8281c933 214Or using L<Config::General>:
215
216 <Model::FilmDB>
217 schema_class MyApp::Schema::FilmDB
c34bcab6 218 traits Caching
8281c933 219 <connect_info>
2201c2e4 220 dsn dbi:Pg:dbname=mypgdb
221 user postgres
42e14c31 222 password ""
2201c2e4 223 auto_savepoint 1
f24a5fbb 224 quote_names 1
8281c933 225 on_connect_do some SQL statement
226 on_connect_do another SQL statement
227 </connect_info>
b9cc2f76 228 user_defined_schema_accessor foo
8281c933 229 </Model::FilmDB>
230
231or
232
233 <Model::FilmDB>
234 schema_class MyApp::Schema::FilmDB
235 connect_info dbi:SQLite:dbname=foo.db
236 </Model::FilmDB>
237
2201c2e4 238Or using L<YAML>:
239
240 Model::MyDB:
241 schema_class: MyDB
b9cc2f76 242 traits: Caching
2201c2e4 243 connect_info:
244 dsn: dbi:Oracle:mydb
245 user: mtfnpy
246 password: mypass
247 LongReadLen: 1000000
248 LongTruncOk: 1
b9cc2f76 249 on_connect_call: 'datetime_setup'
f24a5fbb 250 quote_names: 1
2201c2e4 251
252The old arrayref style with hashrefs for L<DBI> then L<DBIx::Class> options is also
253supported:
254
255 connect_info => [
256 'dbi:Pg:dbname=mypgdb',
257 'postgres',
258 '',
259 {
260 pg_enable_utf8 => 1,
261 },
262 {
0fbbc8d5 263 auto_savepoint => 1,
2201c2e4 264 on_connect_do => [
265 'some SQL statement',
266 'another SQL statement',
267 ],
268 }
269 ]
270
c34bcab6 271=head2 traits
0fbbc8d5 272
41bcf32f 273Array of Traits to apply to the instance. Traits are L<Moose::Role>s.
274
d816d7bf 275They are relative to the C<< MyApp::TraitFor::Model::DBIC::Schema:: >>, then
276the C<< Catalyst::TraitFor::Model::DBIC::Schema:: >> namespaces, unless
277prefixed with C<+> in which case they are taken to be a fully qualified name.
278E.g.:
2201c2e4 279
c34bcab6 280 traits Caching
fb691af9 281 traits +MyApp::TraitFor::Model::Foo
2201c2e4 282
0fbbc8d5 283A new instance is created at application time, so any consumed required
284attributes, coercions and modifiers will work.
2201c2e4 285
fb691af9 286Traits are applied at L<Catalyst::Component/COMPONENT> time using
287L<CatalystX::Component::Traits>.
0fbbc8d5 288
41bcf32f 289C<ref $self> will be an anon class if any traits are applied, C<<
290$self->_original_class_name >> will be the original class.
f090a149 291
c7d7b849 292When writing a Trait, interesting points to modify are C<BUILD>, L</setup> and
293L</ACCEPT_CONTEXT>.
0fbbc8d5 294
c34bcab6 295Traits that come with the distribution:
0fbbc8d5 296
297=over 4
2201c2e4 298
fb691af9 299=item L<Catalyst::TraitFor::Model::DBIC::Schema::Caching>
0fbbc8d5 300
fb691af9 301=item L<Catalyst::TraitFor::Model::DBIC::Schema::Replicated>
c4fee9b8 302
d816d7bf 303=item L<Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy>
304
b75fb6c1 305=item L<Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema>
306
0fbbc8d5 307=back
8281c933 308
2a5644e8 309=head2 compose_namespaces
310
311This model calls L<DBIx::Class::Schema/compose_namespaces> by default to
312install classes into the model namespaces. You can turn that off by
313setting this attribute to false. Default is true.
314
315=head2 install_model_shortcuts
316
317If you don't want shortcut models so you can do e.g. C<< $c->model('DB::Book')
318>> set this attribute to false, Default is true.
319
c4fee9b8 320=head2 storage_type
ad91060a 321
322Allows the use of a different C<storage_type> than what is set in your
323C<schema_class> (which in turn defaults to C<::DBI> if not set in current
f1613faa 324L<DBIx::Class>). Completely optional, and probably unnecessary for most
325people until other storage backends become available for L<DBIx::Class>.
ad91060a 326
c7d7b849 327=head1 ATTRIBUTES
328
329The keys you pass in the model configuration are available as attributes.
330
331Other attributes available:
332
333=head2 connect_info
334
335Your connect_info args normalized to hashref form (with dsn/user/password.) See
336L<DBIx::Class::Storage::DBI/connect_info> for more info on the hashref form of
337L</connect_info>.
338
339=head2 model_name
340
341The model name L<Catalyst> uses to resolve this model, the part after
342C<::Model::> or C<::M::> in your class name. E.g. if your class name is
343C<MyApp::Model::DB> the L</model_name> will be C<DB>.
344
c7d7b849 345=head2 _default_cursor_class
346
6f6b9c2d 347What to reset your L<DBIx::Class::Storage::DBI/cursor_class> to if a custom one
c7d7b849 348doesn't work out. Defaults to L<DBIx::Class::Storage::DBI::Cursor>.
349
fb691af9 350=head1 ATTRIBUTES FROM L<MooseX::Traits::Pluggable>
351
352=head2 _original_class_name
353
354The class name of your model before any L</traits> are applied. E.g.
355C<MyApp::Model::DB>.
356
c7d7b849 357=head2 _traits
358
6f6b9c2d 359Unresolved arrayref of traits passed in the config.
c7d7b849 360
361=head2 _resolved_traits
362
363Traits you used resolved to full class names.
364
21d8159f 365=head1 CONFIGURING YOUR SCHEMA AND RESULTSETS
366
367See the documentation for
368L<Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy> for instructions on how
369to pass config values from your L<Catalyst> config to your
370L<DBIx::Class::Schema> and/or L<DBIx::Class::ResultSet> classes.
371
ad91060a 372=head1 METHODS
373
c4fee9b8 374=head2 new
ad91060a 375
376Instantiates the Model based on the above-documented ->config parameters.
0f2fd2c0 377The only required parameter is C<schema_class>. C<connect_info> is
378required in the case that C<schema_class> does not already have connection
379information defined for it.
ad91060a 380
c4fee9b8 381=head2 schema
f1613faa 382
383Accessor which returns the connected schema being used by the this model.
384There are direct shortcuts on the model class itself for
385schema->resultset, schema->source, and schema->class.
386
c4fee9b8 387=head2 composed_schema
f1613faa 388
389Accessor which returns the composed schema, which has no connection info,
2a5644e8 390which was used in constructing the L</schema>. Useful for creating
f1613faa 391new connections based on the same schema/model. There are direct shortcuts
392from the model object for composed_schema->clone and composed_schema->connect
393
2a5644e8 394If L</compose_namespaces> is not true, L</composed_schema> is equivalent to
395C<< $model->schema_class->clone >>.
396
c4fee9b8 397=head2 clone
f1613faa 398
399Shortcut for ->composed_schema->clone
400
c4fee9b8 401=head2 connect
f1613faa 402
403Shortcut for ->composed_schema->connect
404
c4fee9b8 405=head2 source
c12b7310 406
f1613faa 407Shortcut for ->schema->source
408
c4fee9b8 409=head2 class
f1613faa 410
411Shortcut for ->schema->class
412
c4fee9b8 413=head2 resultset
f1613faa 414
415Shortcut for ->schema->resultset
416
d816d7bf 417=head2 txn_do
418
419Shortcut for ->schema->txn_do
420
421=head2 txn_scope_guard
422
423Shortcut for ->schema->txn_scope_guard
424
c4fee9b8 425=head2 storage
f1613faa 426
427Provides an accessor for the connected schema's storage object.
21d8159f 428
429See L<DBIx::Class::Storage> and L<DBIx::Class::Storage::DBI>.
b8427e0b 430
ad91060a 431=cut
432
c34bcab6 433has schema_class => (
0fbbc8d5 434 is => 'ro',
2fa0a1f1 435 isa => SchemaClass,
0fbbc8d5 436 required => 1
437);
438
0f64d02c 439has compose_namespaces => (is => 'ro', isa => Bool, default => 1 );
2a5644e8 440
0f64d02c 441has install_model_shortcuts => (is => 'ro', isa => Bool, default => 1 );
2a5644e8 442
c34bcab6 443has storage_type => (is => 'rw', isa => Str);
0fbbc8d5 444
18b829f0 445has connect_info => (is => 'rw', isa => ConnectInfo, coerce => 1);
0fbbc8d5 446
c7d7b849 447has model_name => (
448 is => 'ro',
449 isa => Str,
450 required => 1,
451 lazy_build => 1,
452);
ad91060a 453
c34bcab6 454has _default_cursor_class => (
61ed82a5 455 is => 'ro',
45b10191 456 isa => LoadableClass,
61ed82a5 457 default => 'DBIx::Class::Storage::DBI::Cursor',
61ed82a5 458);
459
d816d7bf 460has schema => (is => 'rw', isa => Schema);
461
21d8159f 462my $app_class;
463
464before COMPONENT => sub {
465 $app_class = ref $_[1] || $_[1];
466};
467
468sub app_class { $app_class }
469
0fbbc8d5 470sub BUILD {
f27a05ea 471 my ($self, $args) = @_;
f2488839 472 my $class = $self->_original_class_name;
2201c2e4 473 my $schema_class = $self->schema_class;
ad91060a 474
2201c2e4 475 if( !$self->connect_info ) {
f1613faa 476 if($schema_class->storage && $schema_class->storage->connect_info) {
2201c2e4 477 $self->connect_info($schema_class->storage->connect_info);
f1613faa 478 }
479 else {
39f5f008 480 die "Either ->config->{connect_info} must be defined for $class"
460e3ac8 481 . " or $schema_class must have connect info defined on it."
482 . " Here's what we got:\n"
ae3d05c2 483 . Dumper($args);
f1613faa 484 }
7db6da78 485 }
486
0fbbc8d5 487 if (exists $self->connect_info->{cursor_class}) {
45b10191 488 eval { use_module($self->connect_info->{cursor_class}) }
0fbbc8d5 489 or croak "invalid connect_info: Cannot load your cursor_class"
490 . " ".$self->connect_info->{cursor_class}.": $@";
491 }
492
d816d7bf 493 $self->setup($args);
0fbbc8d5 494
d816d7bf 495 my $is_installed = defined $self->composed_schema;
2201c2e4 496
2a5644e8 497 if (not $is_installed) {
498 $self->composed_schema($self->compose_namespaces ?
499 $schema_class->compose_namespace($class)
500 :
501 $schema_class->clone
502 );
503 }
46a2eb0c 504
ae3d05c2 505 $self->schema($self->composed_schema->clone)
506 unless $self->schema;
f1613faa 507
2201c2e4 508 $self->schema->storage_type($self->storage_type)
509 if $self->storage_type;
7db6da78 510
2201c2e4 511 $self->schema->connection($self->connect_info);
512
2a5644e8 513 if ((not $is_installed) && $self->install_model_shortcuts) {
514 $self->_install_rs_models;
515 }
2201c2e4 516}
517
518sub clone { shift->composed_schema->clone(@_); }
519
520sub connect { shift->composed_schema->connect(@_); }
521
ae3d05c2 522# some proxy methods, see also SchemaProxy
d816d7bf 523
524sub resultset { shift->schema->resultset(@_); }
525
526sub txn_do { shift->schema->txn_do(@_); }
527
528sub txn_scope_guard { shift->schema->txn_scope_guard(@_); }
529
1d67a585 530sub storage { shift->schema->storage(@_); }
531
c4fee9b8 532=head2 setup
2201c2e4 533
e203cd42 534Called at C<BUILD> time before configuration, but after L</connect_info> is
c7d7b849 535set. To do something after configuuration use C<< after BUILD => >>.
2201c2e4 536
d816d7bf 537Receives a hashref of args passed to C<BUILD>.
538
2201c2e4 539=cut
540
0fbbc8d5 541sub setup { 1 }
2201c2e4 542
c4fee9b8 543=head2 ACCEPT_CONTEXT
2201c2e4 544
73f72d28 545Point of extension for doing things at C<< $c->model >> time with context,
546returns the model instance, see L<Catalyst::Manual::Intro/ACCEPT_CONTEXT> for
547more information.
2201c2e4 548
0fbbc8d5 549=cut
2201c2e4 550
0fbbc8d5 551sub ACCEPT_CONTEXT { shift }
2201c2e4 552
553sub _install_rs_models {
554 my $self = shift;
7b1fe8c2 555 my $class = $self->_original_class_name;
2201c2e4 556
ad91060a 557 no strict 'refs';
39f5f008 558
559 my @sources = $self->schema->sources;
560
ca7cf6f0 561 unless (@sources) {
562 warn <<'EOF' unless $ENV{CMDS_NO_SOURCES};
563******************************* WARNING ***************************************
564* No sources found (did you forget to define your tables?) *
565* *
566* To turn off this warning, set the CMDS_NO_SOURCES environment variable. *
567*******************************************************************************
568EOF
569 }
39f5f008 570
571 foreach my $moniker (@sources) {
0b2a7108 572 my $classname = "${class}::$moniker";
7db6da78 573 *{"${classname}::ACCEPT_CONTEXT"} = sub {
ad91060a 574 shift;
2201c2e4 575 shift->model($self->model_name)->resultset($moniker);
ad91060a 576 }
577 }
2201c2e4 578}
ad91060a 579
61ed82a5 580sub _reset_cursor_class {
581 my $self = shift;
582
583 if ($self->storage->can('cursor_class')) {
584 $self->storage->cursor_class($self->_default_cursor_class)
585 if $self->storage->cursor_class ne $self->_default_cursor_class;
586 }
587}
588
50f488ec 589{
590 my %COMPOSED_CACHE;
591
592 sub composed_schema {
593 my $self = shift;
594 my $class = $self->_original_class_name;
595 my $store = \$COMPOSED_CACHE{$class}{$self->schema_class};
596
597 $$store = shift if @_;
598
599 return $$store
600 }
601}
602
c7d7b849 603sub _build_model_name {
604 my $self = shift;
605 my $class = $self->_original_class_name;
606 (my $model_name = $class) =~ s/^[\w:]+::(?:Model|M):://;
607
608 return $model_name;
41bcf32f 609}
610
0fbbc8d5 611__PACKAGE__->meta->make_immutable;
2201c2e4 612
ca7cf6f0 613=head1 ENVIRONMENT
614
615=over 4
616
617=item CMDS_NO_SOURCES
618
cbe03ea7 619Set this variable if you will be using schemas with no sources (Result classes)
620to disable the warning. The warning is there because having no Result classes
621is usually a mistake.
ca7cf6f0 622
623=back
624
95b41ca8 625=head1 Setting up DBIC authentication
626
627You can set this up with
628L<Catalyst::Authentication::Store::DBIx::Class> in MyApp.pm:
629
630 package MyApp;
631
632 use Catalyst qw/... Authentication .../;
633
634 ...
635
10c73a30 636 __PACKAGE__->config('Plugin::Authentication' =>
637 {
95b41ca8 638 default_realm => 'members',
10c73a30 639 members => {
640 credential => {
641 class => 'Password',
642 password_field => 'password',
643 password_type => 'hashed'
644 password_hash_type => 'SHA-256'
645 },
646 store => {
647 class => 'DBIx::Class',
648 user_model => 'DB::User',
649 role_relation => 'roles',
650 role_field => 'rolename',
95b41ca8 651 }
652 }
10c73a30 653 });
95b41ca8 654
ae3d05c2 655=head1 METHOD PROXYING
656
657The automatic proxying to the underlying L<DBIx::Class::Schema> has been
658removed as of version C<0.34>, to enable this feature add C<SchemaProxy> to
659L</traits>.
660
661See L<Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy>.
662
ad91060a 663=head1 SEE ALSO
664
7b39f3f0 665General Catalyst Stuff:
666
667L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
668L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
669
670Stuff related to DBIC and this Model style:
671
672L<DBIx::Class>, L<DBIx::Class::Schema>,
f090a149 673L<DBIx::Class::Schema::Loader>, L<Catalyst::Helper::Model::DBIC::Schema>,
e203cd42 674L<CatalystX::Component::Traits>, L<MooseX::Traits::Pluggable>
ad91060a 675
c34bcab6 676Traits:
c4fee9b8 677
fb691af9 678L<Catalyst::TraitFor::Model::DBIC::Schema::Caching>,
cbe03ea7 679L<Catalyst::TraitFor::Model::DBIC::Schema::Replicated>,
d816d7bf 680L<Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy>,
b75fb6c1 681L<Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema>,
cbe03ea7 682L<Catalyst::TraitFor::Model::DBIC::Schema::QueryLog>
c4fee9b8 683
ad91060a 684=head1 AUTHOR
685
e203cd42 686Brandon L Black C<blblack at gmail.com>
ad91060a 687
e203cd42 688=head1 CONTRIBUTORS
2ff00e2b 689
e203cd42 690caelum: Rafael Kitover C<rkitover at cpan.org>
2ff00e2b 691
4e251d1a 692dandv: Dan Dascalescu C<dandv at cpan.org>
6d9e2623 693
4e251d1a 694bluefeet: Aran Deltac C<bluefeet@cpan.org>
695
696t0m: Tomas Doran C<bobtfish@bobtfish.net>
697
698osfameron: C<osfameron@cpan.org>
49c75c04 699
cbe03ea7 700ozum: Ozum Eldogan C<ozum@ozum.net>
ce9e19dc 701
87145c6c 702Pavel I. Shaydo C<zwon@trinitum.org>
703
566a0bca 704SineSwiper: Brendan Byrd <byrd.b@insightcom.com>
b75fb6c1 705
ad91060a 706=head1 COPYRIGHT
707
21d8159f 708Copyright (c) 2006 - 2010
4e251d1a 709the Catalyst::Model::DBIC::Schema L</AUTHOR> and L</CONTRIBUTORS>
710as listed above.
711
712=head1 LICENSE
713
6d9e2623 714This program is free software. You can redistribute it and/or modify it
ad91060a 715under the same terms as Perl itself.
716
717=cut
718
7191;
21d8159f 720# vim:sts=4 sw=4 et tw=80: