first pass at changes related to Schema::Loader 0.03, and unification of the two...
Brandon L. Black [Mon, 22 May 2006 03:57:26 +0000 (03:57 +0000)]
Build.PL
Makefile.PL
lib/Catalyst/Helper/Model/DBIC/Schema.pm
lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm [deleted file]
lib/Catalyst/Model/DBIC/Schema.pm

index d5067e4..46664a3 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -5,14 +5,14 @@ my %arguments = (
     license            => 'perl',
     module_name        => 'Catalyst::Model::DBIC::Schema',
     requires           => {
-        'DBIx::Class'           => 0.05007,
+        'DBIx::Class'           => 0.06,
         'Catalyst'              => 5.64,
         'UNIVERSAL::require'    => 0.10,
         'Class::Data::Accessor' => 0.02,
         'Class::Accessor::Fast' => 0.22,
     },
     recommends         => {
-        'DBIx::Class::Schema::Loader' => '0.02007',
+        'DBIx::Class::Schema::Loader' => '0.03',
     },
     build_requires     => {
         'Test::More'            => 0.32,
index 51d31fd..192903a 100644 (file)
       
       # Save this 'cause CPAN will chdir all over the place.
       my $cwd = Cwd::cwd();
-      my $makefile = File::Spec->rel2abs($0);
       
-      CPAN::Shell->install('Module::Build::Compat')
-       or die " *** Cannot install without Module::Build.  Exiting ...\n";
+      CPAN::Shell->install('Module::Build::Compat');
+      CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
+       or die "Couldn't install Module::Build, giving up.\n";
       
       chdir $cwd or die "Cannot chdir() back to $cwd: $!";
     }
     eval "use Module::Build::Compat 0.02; 1" or die $@;
-    use lib '_build/lib';
+    
     Module::Build::Compat->run_build_pl(args => \@ARGV);
     require Module::Build;
     Module::Build::Compat->write_makefile(build_class => 'Module::Build');
index 12d6cbd..6f4ff9d 100644 (file)
@@ -10,27 +10,57 @@ Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
 
 =head1 SYNOPSIS
 
-  script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ connect_info arguments ]
+  script/create.pl model ModelName DBIC::Schema My::SchemaClass [ create=dynamic | create=static ] [ connect_info arguments ]
 
-  Where:
-    Foo is the short name for the Model class being generated
-    Foo::SchemaClass is the fully qualified classname of your Schema,
-      which isa DBIx::Class::Schema defined elsewhere.
+=head1 DESCRIPTION
+
+Helper for the DBIC Schema Models.
+
+=head2 Arguments:
+
+    ModelName is the short name for the Model class being generated
+
+    My::SchemaClass is the fully qualified classname of your Schema,
+      which might or might not yet exist.
+
+    create=dynamic instructs this Helper to generate the named Schema
+      class for you, basing it on L<DBIx::Class::Schema::Loader> (which
+      means the table information will always be dynamically loaded at
+      runtime from the database).
+
+    create=static instructs this Helper to generate the named Schema
+      class for you, using L<DBIx::Class::Schema::Loader> in "one shot"
+      mode to create a standard, manually-defined L<DBIx::Class::Schema>
+      setup, based on what the Loader sees in your database at this moment.
+      A Schema/Model pair generated this way will not require
+      L<DBIx::Class::Schema::Loader> at runtime, and will not automatically
+      adapt itself to changes in your database structure.  You can edit
+      the generated classes by hand to refine them.
+      
     connect_info arguments are the same as what DBIx::Class::Schema::connect
       expects, and are storage_type-specific.  For DBI-based storage, these
       arguments are the dsn, username, password, and connect options,
-      respectively.
+      respectively.  These are optional for existing Schemas, but required
+      if you use either of the C<create=> options.
+
+Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
 
 =head1 TYPICAL EXAMPLES
 
-  script/myapp_create.pl model Foo DBIC::Schema FooSchema dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }'
+  # Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
+  #  and a Model which references it:
+  script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=static dbi:mysql:foodb myuname mypass
 
-  # -or, if the schema already has connection info and you want to re-use that:
-  script/myapp_create.pl model Foo DBIC::Schema FooSchema
+  # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
+  #  and a Model which references it:
+  script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
 
-=head1 DESCRIPTION
+  # Reference an existing Schema of any kind, and provide some connection information for ->config:
+  script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass dbi:mysql:foodb myuname mypass
 
-Helper for the DBIC Schema Models.
+  # Same, but don't supply connect information yet (you'll need to do this
+  #  in your app config, or [not recommended] in the schema itself).
+  script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass
 
 =head2 METHODS
 
@@ -41,7 +71,14 @@ Helper for the DBIC Schema Models.
 sub mk_compclass {
     my ( $self, $helper, $schema_class, @connect_info) = @_;
 
-    $helper->{schema_class} = $schema_class || '';
+    $helper->{schema_class} = $schema_class
+        or die "Must supply schema class name";
+
+    my $create = '';
+    if($connect_info[0] && $connect_info[0] =~ /^create=(dynamic|static)$/) {
+        $create = $1;
+        shift @connect_info;
+    }
 
     if(@connect_info) {
         $helper->{setup_connect_info} = 1;
@@ -53,6 +90,21 @@ sub mk_compclass {
 
     my $file = $helper->{file};
     $helper->render_file( 'compclass', $file );
+
+    if($create eq 'dynamic') {
+        my @schema_parts = split(/\:\:/, $helper->{schema_class});
+        my $schema_file_part = pop @schema_parts;
+
+        my $schema_dir  = File::Spec->catfile( $helper->{base}, 'lib', @schema_parts );
+        my $schema_file = File::Spec->catfile( $schema_dir, $schema_file_part . '.pm' );
+
+        $helper->mk_dir($schema_dir);
+        $helper->render_file( 'schemaclass', $schema_file );
+    }
+    elsif($create eq 'static') {
+       die "Unimplemented ...";
+       # XXX make a loader class in memory with dumpdir set to our base+lib, and load it.
+    }
 }
 
 =head1 SEE ALSO
@@ -85,6 +137,42 @@ __DATA__
 
 =begin pod_to_ignore
 
+__schemaclass__
+package [% schema_class %];
+
+use strict;
+use base qw/DBIx::Class::Schema::Loader/;
+
+__PACKAGE__->loader_options(
+    relationships => 1,
+    # debug => 1,
+);
+
+=head1 NAME
+
+[% schema_class %] - DBIx::Class::Schema::Loader class
+
+=head1 SYNOPSIS
+
+See L<[% app %]>
+
+=head1 DESCRIPTION
+
+Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
+
+=head1 AUTHOR
+
+[% author %]
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
+
 __compclass__
 package [% class %];
 
@@ -102,15 +190,13 @@ __PACKAGE__->config(
 =head1 NAME
 
 [% class %] - Catalyst DBIC Schema Model
-
 =head1 SYNOPSIS
 
 See L<[% app %]>
 
 =head1 DESCRIPTION
 
-L<Catalyst::Model::DBIC::Schema> Model using schema
-L<[% schema_class %]>
+L<Catalyst::Model::DBIC::Schema> Model using schema L<[% schema_class %]>
 
 =head1 AUTHOR
 
diff --git a/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm b/lib/Catalyst/Helper/Model/DBIC/SchemaLoader.pm
deleted file mode 100644 (file)
index 9cf27ab..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-package Catalyst::Helper::Model::DBIC::SchemaLoader;
-
-use strict;
-use warnings;
-use Carp;
-
-=head1 NAME
-
-Catalyst::Helper::Model::DBIC::SchemaLoader - Helper for AutoLoaded DBIC Schema Models
-
-=head1 SYNOPSIS
-
-  script/myapp_create.pl model Foo DBIC::SchemaLoader [ connect info arguments ]
-
-  Where:
-    Foo is the short name for the Model class being generated
-    connect_info arguments are the same as what DBIx::Class::Schema::connect
-      expects, and are storage_type-specific.  For DBI-based storage, these
-      arguments are the dsn, username, password, and connect options,
-      respectively.
-
-=head1 TYPICAL EXAMPLE
-
-  script/myapp_create.pl model Foo DBIC::SchemaLoader dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }'
-
-=head1 DESCRIPTION
-
-This helper generates two classes:
-
-First, it generates a L<DBIx::Class::Schema::Loader> class at
-F<lib/MyApp/SchemaLoader/Foo.pm> based on your supplied dsn/user/pass.
-
-Then, it generates a L<Catalyst::Model::DBIC::Schema> at
-F<lib/MyApp/M/Foo.pm>, which references the above-generated loader.
-
-Models generated by this Helper require the seperate package
-L<DBIx::Class::Schema::Loader> to be installed.  It is on the recommended
-list for this package, but is not required for installation.
-
-=head2 METHODS
-
-=head3 mk_compclass
-
-=cut
-
-sub mk_compclass {
-    my ($self, $helper, @connect_info) = @_;
-
-    for(@connect_info) {
-        $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
-    }
-
-    $helper->{loader_class} = $helper->{class};
-    $helper->{loader_class} =~ s/\:\:M(?:odel)?\:\:/::SchemaLoader::/;
-    my @loader_parts = split(/\:\:/, $helper->{loader_class});
-    my $loader_file_part = pop @loader_parts;
-
-    my $loader_dir  = File::Spec->catfile( $helper->{base}, 'lib', @loader_parts );
-    my $loader_file = File::Spec->catfile( $loader_dir, $loader_file_part . '.pm' );
-
-    $helper->mk_dir($loader_dir);
-    $helper->{connect_info} = \@connect_info;
-
-    $helper->mk_dir( $loader_dir );
-    $helper->render_file( 'loaderclass', $loader_file );
-
-
-    my $file = $helper->{file};
-    $helper->render_file( 'compclass', $file );
-}
-
-=head1 SEE ALSO
-
-General Catalyst Stuff:
-
-L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
-L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
-
-Stuff related to DBIC and this Model style:
-
-L<DBIx::Class>, L<DBIx::Class::Schema>,
-L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
-L<Catalyst::Helper::Model::DBIC::Schema>
-
-=head1 AUTHOR
-
-Brandon L Black, C<blblack@gmail.com>
-
-=head1 LICENSE
-
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-1;
-
-__DATA__
-
-=begin pod_to_ignore
-
-__loaderclass__
-package [% loader_class %];
-
-use strict;
-use base qw/DBIx::Class::Schema::Loader/;
-
-__PACKAGE__->load_from_connection(
-    connect_info => [
-        [% FOREACH arg = connect_info %][% arg %],
-        [% END %]
-    ],
-    relationships => 1,
-    # debug => 1,
-);
-
-=head1 NAME
-
-[% loader_class %] - Loader-generated DBIx::Class::Schema class
-
-=head1 SYNOPSIS
-
-See L<[% app %]>
-
-=head1 DESCRIPTION
-
-Generated by L<Catalyst::Model::DBIC::Schema> for use in L<[% class %]>
-
-=head1 AUTHOR
-
-[% author %]
-
-=head1 LICENSE
-
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-1;
-
-__compclass__
-package [% class %];
-
-use strict;
-use base 'Catalyst::Model::DBIC::Schema';
-
-__PACKAGE__->config(
-    schema_class => '[% loader_class %]',
-);
-
-=head1 NAME
-
-[% class %] - Catalyst DBIC Schema Model
-
-=head1 SYNOPSIS
-
-See L<[% app %]>
-
-=head1 DESCRIPTION
-
-L<Catalyst::Model::DBIC::Schema> Model using L<DBIx::Class::Schema::Loader>
-generated Schema: L<[% loader_class %]>
-
-=head1 AUTHOR
-
-[% author %]
-
-=head1 LICENSE
-
-This library is free software, you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-1;
-
index fd987ad..b0e8ac8 100644 (file)
@@ -7,7 +7,7 @@ use UNIVERSAL::require;
 use Carp;
 require DBIx::Class;
 
-our $VERSION = '0.12';
+our $VERSION = '0.13';
 
 __PACKAGE__->mk_classaccessor('composed_schema');
 __PACKAGE__->mk_accessors('schema');
@@ -159,8 +159,7 @@ This is an arrayref of connection parameters, which are specific to your
 C<storage_type> (see your storage type documentation for more details).
 
 This is not required if C<schema_class> already has connection information
-defined in itself (which would be the case for a Schema defined by
-L<DBIx::Class::Schema::Loader>, for instance).
+defined inside itself (which isn't highly recommended, but can be done)
 
 For L<DBIx::Class::Storage::DBI>, which is the only supported
 C<storage_type> in L<DBIx::Class> at the time of this writing, the
@@ -294,7 +293,7 @@ sub new {
     # XXX This is temporary, until DBIx::Class::Storage::DBI supports the
     #  same syntax and we switch our requisite to that version somewhere
     #  down the line.  This syntax is already committed into DBIx::Class
-    #  dev branch post-0.06.
+    #  -current branch post-0.06.
     # At that time, this whole block can revert back to just being:
     #  $self->schema->connection(@{$self->{connect_info}});