The first thing I do before adding my own code to the generated schema
classes is to replace all __PACKAGE__ occurrences to $pkg and add

 my $pkg = __PACKAGE__;

at the top of the file. I've seen someone else doing it and I thought
it made my schema classes a little bit more aesthetically pleasing so
it became one of my own best practices.

I also think that some line breaks here and there make a lot of
difference in code that will actually be handled by human beings.

So, attached you'll find a patch for DBIx::Class::Schema::Loader::Base
(against trunk) that implements these changes. I don't know if this is
generally seen as a good practice (I don't know about any reasons why
it shouldn't) but I've scared enough people with that __PACKAGE__
madness to have it lurking around my own code. But I guess this really
boils down to what everyone else prefers (and, maybe more importantly,
what blblack prefers ;-) ).

I also thought about maybe adding some comments above each of the
generated classes "sections" (e.g. columns, relationships, etc) since
it might help people who are just starting using the module and it's
is also something I usually manually add. But these aren't included in
the patch since I wasn't sure about the best wording.

-Nilson Santos F. Jr.
Index: Base.pm
===================================================================
--- Base.pm	(revision 2221)
+++ Base.pm	(working copy)
@@ -391,6 +391,7 @@
         print $src_fh qq|package $src_class;\n\n$tagline\n\n|;
         print $src_fh qq|use strict;\nuse warnings;\n\n|;
         print $src_fh qq|use base 'DBIx::Class';\n\n|;
+        print $src_fh qq|my \$pkg = __PACKAGE__;\n\n|;
         print $src_fh qq|$_\n|
             for @{$self->{_dump_storage}->{$src_class}};
         print $src_fh qq|\n1;\n\n|;
@@ -485,6 +486,7 @@
         my $table_moniker = $self->monikers->{$table};
 
         $self->_dbic_stmt($table_class,'table',$table);
+        $self->_raw_stmt($table_class,"");
 
         my $cols = $self->_table_columns($table);
         my $col_info;
@@ -500,12 +502,15 @@
             );
         }
 
+        $self->_raw_stmt($table_class,"");
+
         my $pks = $self->_table_pk_info($table) || [];
         @$pks ? $self->_dbic_stmt($table_class,'set_primary_key',@$pks)
               : carp("$table has no primary key");
 
         my $uniqs = $self->_table_uniq_info($table) || [];
         $self->_dbic_stmt($table_class,'add_unique_constraint',@$_) for (@$uniqs);
+        $self->_raw_stmt($table_class,"");
 
         $schema_class->register_class($table_moniker, $table_class);
         $schema->register_class($table_moniker, $table_class) if $schema ne $schema_class;
@@ -609,7 +614,7 @@
 
     warn qq|$class\->$stmt\n| if $self->debug;
     $class->$method(@_);
-    $self->_raw_stmt($class, '__PACKAGE__->' . $stmt);
+    $self->_raw_stmt($class, '$pkg->' . $stmt);
 }
 
 # Store a raw source line for a class (for dumping purposes)
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to