Standardize examples/docs on Schema::Loader schema naming
Peter Rabbitson [Mon, 26 Aug 2013 01:57:42 +0000 (03:57 +0200)]
A new user is very likely to encounter this naming convention these days

12 files changed:
examples/Schema/MyApp/Schema.pm [moved from examples/Schema/MyDatabase/Main.pm with 78% similarity]
examples/Schema/MyApp/Schema/Result/Artist.pm [moved from examples/Schema/MyDatabase/Main/Result/Artist.pm with 63% similarity]
examples/Schema/MyApp/Schema/Result/Cd.pm [moved from examples/Schema/MyDatabase/Main/Result/Cd.pm with 50% similarity]
examples/Schema/MyApp/Schema/Result/Track.pm [moved from examples/Schema/MyDatabase/Main/Result/Track.pm with 63% similarity]
examples/Schema/insertdb.pl [changed mode: 0644->0755]
examples/Schema/testdb.pl [changed mode: 0644->0755]
lib/DBIx/Class/Manual/Cookbook.pod
lib/DBIx/Class/Manual/Example.pod
lib/DBIx/Class/Manual/Intro.pod
lib/DBIx/Class/Manual/QuickStart.pod
lib/DBIx/Class/Schema.pm
lib/DBIx/Class/Storage/DBI/mysql.pm

similarity index 78%
rename from examples/Schema/MyDatabase/Main.pm
rename to examples/Schema/MyApp/Schema.pm
index 6217cac..3642e82 100644 (file)
@@ -1,4 +1,4 @@
-package MyDatabase::Main;
+package MyApp::Schema;
 
 use warnings;
 use strict;
@@ -1,4 +1,4 @@
-package MyDatabase::Main::Result::Artist;
+package MyApp::Schema::Result::Artist;
 
 use warnings;
 use strict;
@@ -11,7 +11,7 @@ __PACKAGE__->add_columns(qw/ artistid name /);
 
 __PACKAGE__->set_primary_key('artistid');
 
-__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
+__PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd');
 
 1;
 
similarity index 50%
rename from examples/Schema/MyDatabase/Main/Result/Cd.pm
rename to examples/Schema/MyApp/Schema/Result/Cd.pm
index 9dc1f4e..6d600a1 100644 (file)
@@ -1,4 +1,4 @@
-package MyDatabase::Main::Result::Cd;
+package MyApp::Schema::Result::Cd;
 
 use warnings;
 use strict;
@@ -11,7 +11,7 @@ __PACKAGE__->add_columns(qw/ cdid artist title year /);
 
 __PACKAGE__->set_primary_key('cdid');
 
-__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist');
-__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track');
+__PACKAGE__->belongs_to('artist' => 'MyApp::Schema::Result::Artist');
+__PACKAGE__->has_many('tracks' => 'MyApp::Schema::Result::Track');
 
 1;
@@ -1,4 +1,4 @@
-package MyDatabase::Main::Result::Track;
+package MyApp::Schema::Result::Track;
 
 use warnings;
 use strict;
@@ -11,6 +11,6 @@ __PACKAGE__->add_columns(qw/ trackid cd title/);
 
 __PACKAGE__->set_primary_key('trackid');
 
-__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
+__PACKAGE__->belongs_to('cd' => 'MyApp::Schema::Result::Cd');
 
 1;
old mode 100644 (file)
new mode 100755 (executable)
index a701795..15bf71b
@@ -3,9 +3,9 @@
 use strict;
 use warnings;
 
-use MyDatabase::Main;
+use MyApp::Schema;
 
-my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
 
 #  here's some of the sql that is going to be generated by the schema
 #  INSERT INTO artist VALUES (NULL,'Michael Jackson');
old mode 100644 (file)
new mode 100755 (executable)
index a65db0f..3d057fd
@@ -3,9 +3,9 @@
 use warnings;
 use strict;
 
-use MyDatabase::Main;
+use MyApp::Schema;
 
-my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
 # for other DSNs, e.g. MySql, see the perldoc for the relevant dbd
 # driver, e.g perldoc L<DBD::mysql>.
 
index 80ae5d0..36b891e 100644 (file)
@@ -1163,14 +1163,14 @@ as each other and your connecting database user has the proper permissions to th
 To accomplish this one only needs to specify the DB schema name in the table
 declaration, like so...
 
-  package MyDatabase::Main::Artist;
+  package MyApp::Schema::Result::Artist;
   use base qw/DBIx::Class::Core/;
 
   __PACKAGE__->table('database1.artist'); # will use "database1.artist" in FROM clause
 
   __PACKAGE__->add_columns(qw/ artist_id name /);
   __PACKAGE__->set_primary_key('artist_id');
-  __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd');
+  __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd');
 
   1;
 
@@ -1186,7 +1186,7 @@ However, one can dynamically "map" to the proper DB schema by overriding the
 L<connection|DBIx::Class::Schama/connection> method in your Schema class and
 building a renaming facility, like so:
 
-  package MyDatabase::Schema;
+  package MyApp::Schema;
   use Moose;
 
   extends 'DBIx::Class::Schema';
@@ -1232,7 +1232,7 @@ To use this facility, simply add or modify the \%attr hashref that is passed to
 L<connection|DBIx::Class::Schama/connect>, as follows:
 
   my $schema
-    = MyDatabase::Schema->connect(
+    = MyApp::Schema->connect(
       $dsn,
       $user,
       $pass,
index 2d0e2e3..e41945b 100644 (file)
@@ -70,56 +70,56 @@ Change directory back from db to the directory app:
 
 Now create some more directories:
 
-  mkdir MyDatabase
-  mkdir MyDatabase/Main
-  mkdir MyDatabase/Main/Result
-  mkdir MyDatabase/Main/ResultSet
+  mkdir MyApp
+  mkdir MyApp/Schema
+  mkdir MyApp/Schema/Result
+  mkdir MyApp/Schema/ResultSet
 
 Then, create the following DBIx::Class::Schema classes:
 
-MyDatabase/Main.pm:
+MyApp/Schema.pm:
 
-  package MyDatabase::Main;
+  package MyApp::Schema;
   use base qw/DBIx::Class::Schema/;
   __PACKAGE__->load_namespaces;
 
   1;
 
 
-MyDatabase/Main/Result/Artist.pm:
+MyApp/Schema/Result/Artist.pm:
 
-  package MyDatabase::Main::Result::Artist;
+  package MyApp::Schema::Result::Artist;
   use base qw/DBIx::Class::Core/;
   __PACKAGE__->table('artist');
   __PACKAGE__->add_columns(qw/ artistid name /);
   __PACKAGE__->set_primary_key('artistid');
-  __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd');
+  __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd');
 
   1;
 
 
-MyDatabase/Main/Result/Cd.pm:
+MyApp/Schema/Result/Cd.pm:
 
-  package MyDatabase::Main::Result::Cd;
+  package MyApp::Schema::Result::Cd;
   use base qw/DBIx::Class::Core/;
   __PACKAGE__->load_components(qw/InflateColumn::DateTime/);
   __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');
+  __PACKAGE__->belongs_to('artist' => 'MyApp::Schema::Result::Artist');
+  __PACKAGE__->has_many('tracks' => 'MyApp::Schema::Result::Track');
 
   1;
 
 
-MyDatabase/Main/Result/Track.pm:
+MyApp/Schema/Result/Track.pm:
 
-  package MyDatabase::Main::Result::Track;
+  package MyApp::Schema::Result::Track;
   use base qw/DBIx::Class::Core/;
   __PACKAGE__->table('track');
   __PACKAGE__->add_columns(qw/ trackid cd title /);
   __PACKAGE__->set_primary_key('trackid');
-  __PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd');
+  __PACKAGE__->belongs_to('cd' => 'MyApp::Schema::Result::Cd');
 
   1;
 
@@ -133,9 +133,9 @@ insertdb.pl
   use strict;
   use warnings;
 
-  use MyDatabase::Main;
+  use MyApp::Schema;
 
-  my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+  my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
 
   #  here's some of the SQL that is going to be generated by the schema
   #  INSERT INTO artist VALUES (NULL,'Michael Jackson');
@@ -199,9 +199,9 @@ testdb.pl:
   use strict;
   use warnings;
 
-  use MyDatabase::Main;
+  use MyApp::Schema;
 
-  my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+  my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
   # for other DSNs, e.g. MySQL, see the perldoc for the relevant dbd
   # driver, e.g perldoc L<DBD::mysql>.
 
@@ -354,15 +354,15 @@ are available in the main distribution for DBIx::Class under the
 directory F<t/examples/Schema>.
 
 With these scripts we're relying on @INC looking in the current
-working directory.  You may want to add the MyDatabase namespaces to
+working directory.  You may want to add the MyApp namespaces to
 @INC in a different way when it comes to deployment.
 
 The F<testdb.pl> script is an excellent start for testing your database
 model.
 
 This example uses L<DBIx::Class::Schema/load_namespaces> to load in the
-appropriate L<Row|DBIx::Class::Row> classes from the MyDatabase::Main::Result namespace,
-and any required resultset classes from the MyDatabase::Main::ResultSet
+appropriate L<Row|DBIx::Class::Row> classes from the MyApp::Schema::Result namespace,
+and any required resultset classes from the MyApp::Schema::ResultSet
 namespace (although we created the directory in the directions above we
 did not add, or need to add, any resultset classes).
 
index 1360782..f13e14e 100644 (file)
@@ -209,7 +209,7 @@ If you have a mixed-case database, use the C<preserve_case> option, e.g.:
 If you are using L<Catalyst>, then you can use the helper that comes with
 L<Catalyst::Model::DBIC::Schema>:
 
-    $ script/myapp_create.pl model MyDB DBIC::Schema MyDB::Schema \
+    $ script/myapp_create.pl model MyModel DBIC::Schema MyApp::Schema \
         create=static moniker_map='{ foo => "FOO" }' dbi:SQLite:./myapp.db \
         on_connect_do='PRAGMA foreign_keys=ON' quote_char='"'
 
index c589111..9f401f4 100644 (file)
@@ -33,8 +33,8 @@ Inspect the database:
 You can also use a GUI database browser such as
 L<SQLite Manager|https://addons.mozilla.org/firefox/addon/sqlite-manager>.
 
-Have a look at the schema classes files in the subdirectory F<MyDatabase>. The
-C<MyDatabase::Main> class is the entry point for loading the other classes and
+Have a look at the schema classes files in the subdirectory F<MyApp>. The
+C<MyApp::Schema> class is the entry point for loading the other classes and
 interacting with the database through DBIC and the C<Result> classes correspond
 to the tables in the database. L<DBIx::Class::Manual::Example> shows how to
 write all that Perl code. That is almost never necessary, though. Instead use
@@ -46,8 +46,8 @@ chapter L</"Resetting the database"> below shows an example invocation.
 
 A L<schema|DBIx::Class::Manual::Glossary/Schema> object represents the database.
 
-    use MyDatabase::Main qw();
-    my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+    use MyApp::Schema qw();
+    my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
 
 The first four arguments are the same as for L<DBI/connect>.
 
@@ -114,7 +114,7 @@ Set up a condition.
         }
     );
 
-Iterate over result objects of class C<MyDatabase::Main::Result::Artist>.
+Iterate over result objects of class C<MyApp::Schema::Result::Artist>.
 L<Result|DBIx::Class::Manual::Glossary/Result> objects represent a row and
 automatically get accessors for their column names.
 
@@ -175,11 +175,11 @@ From a detail to the root:
     DBIx-Class/examples/Schema$ perl ./insertdb.pl
 
     # delete the schema classes files
-    DBIx-Class/examples/Schema$ rm -rf MyDatabase/
+    DBIx-Class/examples/Schema$ rm -rf MyApp
 
     # recreate schema classes files from database file
     DBIx-Class/examples/Schema$ dbicdump \
-        -o dump_directory=. MyDatabase::Main dbi:SQLite:db/example.db
+        -o dump_directory=. MyApp::Schema dbi:SQLite:db/example.db
 
 =head2 Where to go next
 
index 1df1005..16a0878 100644 (file)
@@ -73,12 +73,13 @@ particular which module inherits off which.
 
 =back
 
+  package MyApp::Schema;
   __PACKAGE__->load_namespaces();
 
   __PACKAGE__->load_namespaces(
      result_namespace => 'Res',
      resultset_namespace => 'RSet',
-     default_resultset_class => '+MyDB::Othernamespace::RSet',
+     default_resultset_class => '+MyApp::Othernamespace::RSet',
   );
 
 With no arguments, this method uses L<Module::Find> to load all of the
index a2aa2fc..83ee8b2 100644 (file)
@@ -176,7 +176,7 @@ DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifi
 Storage::DBI autodetects the underlying MySQL database, and re-blesses the
 C<$storage> object into this class.
 
-  my $schema = MyDb::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } );
+  my $schema = MyApp::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } );
 
 =head1 DESCRIPTION