[Bast-commits] r5013 - in DBIx-Class/0.08/trunk:
lib/DBIx/Class/Manual t/examples/Schema/MyDatabase
t/examples/Schema/MyDatabase/Main
t/examples/Schema/MyDatabase/Main/Result
nigel at dev.catalyst.perl.org
nigel at dev.catalyst.perl.org
Tue Oct 28 09:21:33 GMT 2008
Author: nigel
Date: 2008-10-28 09:21:33 +0000 (Tue, 28 Oct 2008)
New Revision: 5013
Added:
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm
Removed:
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Artist.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Cd.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Track.pm
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Example.pod
DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Intro.pod
DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main.pm
Log:
Merged in documentation modifications for Intro and Example to use load_namespaces syntax
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Example.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Example.pod 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Example.pod 2008-10-28 09:21:33 UTC (rev 5013)
@@ -72,6 +72,8 @@
mkdir MyDatabase
mkdir MyDatabase/Main
+ mkdir MyDatabase/Main/Result
+ mkdir MyDatabase/Main/ResultSet
Then, create the following DBIx::Class::Schema classes:
@@ -79,47 +81,47 @@
package MyDatabase::Main;
use base qw/DBIx::Class::Schema/;
- __PACKAGE__->load_classes(qw/Artist Cd Track/);
+ __PACKAGE__->load_namespaces;
1;
-MyDatabase/Main/Artist.pm:
+MyDatabase/Main/Result/Artist.pm:
- package MyDatabase::Main::Artist;
+ package MyDatabase::Main::Result::Artist;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
- __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd');
+ __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
1;
-MyDatabase/Main/Cd.pm:
+MyDatabase/Main/Result/Cd.pm:
- package MyDatabase::Main::Cd;
+ package MyDatabase::Main::Result::Cd;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('cd');
__PACKAGE__->add_columns(qw/ cdid artist title/);
__PACKAGE__->set_primary_key('cdid');
- __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist');
- __PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Track');
+ __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist');
+ __PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track');
1;
-MyDatabase/Main/Track.pm:
+MyDatabase/Main/Result/Track.pm:
- package MyDatabase::Main::Track;
+ package MyDatabase::Main::Result::Track;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('track');
__PACKAGE__->add_columns(qw/ trackid cd title/);
__PACKAGE__->set_primary_key('trackid');
- __PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Cd');
+ __PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
1;
@@ -356,11 +358,18 @@
The testdb.pl script is an excellent start for testing your database
model.
+This example uses load_namespaces to load in the appropriate Row classes
+from the MyDatabase::Main::Result namespace, and any required resultset
+classes from the MyDatabase::Main::ResultSet namespace (although we
+created the directory in the directions above we did not add, or need to
+add, any resultset classes).
+
=head1 TODO
=head1 AUTHOR
sc_ from irc.perl.org#dbix-class
Kieren Diment <kd at totaldatasolution.com>
+ Nigel Metheringham <nigelm at cpan.org>
=cut
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Intro.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Intro.pod 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Intro.pod 2008-10-28 09:21:33 UTC (rev 5013)
@@ -86,30 +86,25 @@
use base qw/DBIx::Class::Schema/;
In this class you load your result_source ("table", "model") classes, which we
-will define later, using the load_classes() method. You can specify which
-classes to load manually:
+will define later, using the load_namespaces() method:
- # load My::Schema::Album and My::Schema::Artist
- __PACKAGE__->load_classes(qw/ Album Artist /);
+ # load My::Schema::Result::* and their resultset classes
+ __PACKAGE__->load_namespaces();
-Or load classes by namespace:
+By default this loads all the Result (Row) classes in the
+My::Schema::Result:: namespace, and also any resultset classes in the
+My::Schema::ResultSet:: namespace (if missing, the resultsets are
+defaulted to be DBIx::Class::ResultSet objects). You can change the
+result and resultset namespaces by using options to the
+L<DBIx::Class::Schema/load_namespaces> call.
- # load My::Schema::Album, My::Schema::Artist and My::OtherSchema::LinerNotes
- __PACKAGE__->load_classes(
- {
- 'My::Schema' => [qw/ Album Artist /],
- 'My::OtherSchema' => [qw/ LinerNotes /]
- }
- );
+It is also possible to do the same things manually by calling
+C<load_classes> for the Row classes and defining in those classes any
+required resultset classes.
-Or let your schema class load all classes in its namespace automatically:
-
- # load My::Schema::*
- __PACKAGE__->load_classes();
-
Next, create each of the classes you want to load as specified above:
- package My::Schema::Album;
+ package My::Schema::Result::Album;
use base qw/DBIx::Class/;
Load any components required by each class with the load_components() method.
@@ -164,7 +159,7 @@
See L<DBIx::Class::ResultSource> for more details of the possible column
attributes.
-Accessors are created for each column automatically, so My::Schema::Album will
+Accessors are created for each column automatically, so My::Schema::Result::Album will
have albumid() (or album(), when using the accessor), artist() and title()
methods.
@@ -181,7 +176,7 @@
make a predefined accessor for fetching objects that contain this Table's
foreign key:
- __PACKAGE__->has_many('albums', 'My::Schema::Artist', 'album_id');
+ __PACKAGE__->has_many('albums', 'My::Schema::Result::Artist', 'album_id');
See L<DBIx::Class::Relationship> for more information about the various types of
available relationships and how you can design your own.
@@ -248,7 +243,7 @@
my $album = $schema->resultset('Album')->find(14);
This will run a C<SELECT> with C<albumid = 14> in the C<WHERE> clause, and
-return an instance of C<My::Schema::Album> that represents this row. Once you
+return an instance of C<My::Schema::Result::Album> that represents this row. Once you
have that row, you can access and update columns:
$album->title('Physical Graffiti');
@@ -275,7 +270,7 @@
=head2 Adding and removing rows
To create a new record in the database, you can use the C<create> method. It
-returns an instance of C<My::Schema::Album> that can be used to access the data
+returns an instance of C<My::Schema::Result::Album> that can be used to access the data
in the new record:
my $new_album = $schema->resultset('Album')->create({
@@ -384,11 +379,13 @@
=head2 Problems on RHEL5/CentOS5
-There is a problem with slow performance of certain DBIx::Class operations in
-perl-5.8.8-10 and later on RedHat and related systems, due to a bad backport of
-a "use overload" related bug. The problem is in the Perl binary itself, not in
-DBIx::Class. If your system has this problem, you will see a warning on
-startup, with some options as to what to do about it.
+There is a problem with slow performance of certain DBIx::Class
+operations in perl-5.8.8-10 and later on RedHat and related systems, due
+to a bad backport of a "use overload" related bug. The problem is in the
+Perl binary itself, not in DBIx::Class. If your system might suffer this
+problem, you will see a warning on startup, with some options as to what
+to do about it. This problem was eliminated in the perl-5.8.8-15.el5_2.1
+package which was issued in September 2008.
=head1 SEE ALSO
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Artist.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Artist.pm 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Artist.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,10 +0,0 @@
-package MyDatabase::Main::Artist;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('artist');
-__PACKAGE__->add_columns(qw/ artistid name /);
-__PACKAGE__->set_primary_key('artistid');
-__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd');
-
-1;
-
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Cd.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Cd.pm 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Cd.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,10 +0,0 @@
-package MyDatabase::Main::Cd;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('cd');
-__PACKAGE__->add_columns(qw/ cdid artist title/);
-__PACKAGE__->set_primary_key('cdid');
-__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist');
-__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Track');
-
-1;
Copied: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result (from rev 5007, DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result)
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm
===================================================================
--- DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Artist.pm 2008-10-27 20:34:03 UTC (rev 5007)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,10 +0,0 @@
-package MyDatabase::Main::Result::Artist;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('artist');
-__PACKAGE__->add_columns(qw/ artistid name /);
-__PACKAGE__->set_primary_key('artistid');
-__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
-
-1;
-
Copied: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm (from rev 5007, DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Artist.pm)
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm (rev 0)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Artist.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -0,0 +1,10 @@
+package MyDatabase::Main::Result::Artist;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('artist');
+__PACKAGE__->add_columns(qw/ artistid name /);
+__PACKAGE__->set_primary_key('artistid');
+__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
+
+1;
+
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm
===================================================================
--- DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Cd.pm 2008-10-27 20:34:03 UTC (rev 5007)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,10 +0,0 @@
-package MyDatabase::Main::Result::Cd;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('cd');
-__PACKAGE__->add_columns(qw/ cdid artist title/);
-__PACKAGE__->set_primary_key('cdid');
-__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist');
-__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track');
-
-1;
Copied: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm (from rev 5007, DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Cd.pm)
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm (rev 0)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Cd.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -0,0 +1,10 @@
+package MyDatabase::Main::Result::Cd;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('cd');
+__PACKAGE__->add_columns(qw/ cdid artist title/);
+__PACKAGE__->set_primary_key('cdid');
+__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist');
+__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track');
+
+1;
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm
===================================================================
--- DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Track.pm 2008-10-27 20:34:03 UTC (rev 5007)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,9 +0,0 @@
-package MyDatabase::Main::Result::Track;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('track');
-__PACKAGE__->add_columns(qw/ trackid cd title/);
-__PACKAGE__->set_primary_key('trackid');
-__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
-
-1;
Copied: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm (from rev 5007, DBIx-Class/0.08/branches/doc_mods/t/examples/Schema/MyDatabase/Main/Result/Track.pm)
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm (rev 0)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Result/Track.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -0,0 +1,9 @@
+package MyDatabase::Main::Result::Track;
+use base qw/DBIx::Class/;
+__PACKAGE__->load_components(qw/PK::Auto Core/);
+__PACKAGE__->table('track');
+__PACKAGE__->add_columns(qw/ trackid cd title/);
+__PACKAGE__->set_primary_key('trackid');
+__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
+
+1;
Deleted: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Track.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Track.pm 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main/Track.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,9 +0,0 @@
-package MyDatabase::Main::Track;
-use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/PK::Auto Core/);
-__PACKAGE__->table('track');
-__PACKAGE__->add_columns(qw/ trackid cd title/);
-__PACKAGE__->set_primary_key('trackid');
-__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Cd');
-
-1;
Modified: DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main.pm 2008-10-28 09:08:29 UTC (rev 5012)
+++ DBIx-Class/0.08/trunk/t/examples/Schema/MyDatabase/Main.pm 2008-10-28 09:21:33 UTC (rev 5013)
@@ -1,5 +1,5 @@
package MyDatabase::Main;
use base qw/DBIx::Class::Schema/;
-__PACKAGE__->load_classes(qw/Artist Cd Track/);
+__PACKAGE__->load_namespaces;
1;
More information about the Bast-commits
mailing list