Release 0.02
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / lib / DBIx / Class / ResultSource / MultipleTableInheritance.pm
index 3c6b450..980d58b 100644 (file)
@@ -9,9 +9,9 @@ use aliased 'DBIx::Class::ResultSource::Table';
 use aliased 'DBIx::Class::ResultClass::HashRefInflator';
 use String::TT qw(strip tt);
 use Scalar::Util qw(blessed);
-use namespace::autoclean;
+use namespace::autoclean -also => [qw/argify qualify_with body_cols pk_cols names_of function_body arg_hash rule_body/];
 
-our $VERSION = 0.01;
+our $VERSION = 0.02;
 
 __PACKAGE__->mk_group_accessors(simple => qw(parent_source additional_parents));
 
@@ -162,20 +162,6 @@ method attach_additional_sources () {
   );
   $table->set_primary_key($self->primary_columns);
 
-  ## Attempting to re-add sequence here -- AKB
-  #for my $pk ( $self->primary_columns ) {
-    #if ($parent) {
-
-##use 5.012; use Devel::Dwarn; say Dwarn $schema->source($table->_relationships->{parent}->{class}) if $table->_relationships->{parent}->{class};
-      #$table->columns_info->{$pk}->{sequence} =
-        #$self->set_sequence(
-        #$schema->source( $table->_relationships->{parent}->{class} )->name,
-        #$self->primary_columns )
-        #if $table->columns_info->{$pk}->{originally_defined_in} ne $self->name
-          #&& $table->_relationships->{parent}->{class};
-    #}
-  #}
-
   # we need to copy our rels to the raw object as well
   # note that ->add_relationship on a source object doesn't create an
   # accessor so we can leave that part in the attributes
@@ -265,40 +251,41 @@ method add_relationship ($name, $f_source, $cond, $attrs) {
 
 BEGIN {
 
-  # helper routines, constructed as anon subs so autoclean nukes them
-
-  use signatures;
+  # helper routines
 
-  *argify = sub (@names) {
-    map '_'.$_, @names;
-  };
+  sub argify {
+    my @names = @_;
+    map '_' . $_, @names;
+  }
 
-  *qualify_with = sub ($source, @names) {
-    my $name = blessed($source) ? $source->name : $source;
-    map join('.', $name, $_), @names;
-  };
+  sub qualify_with {
+    my $source = shift;
+    my @names  = @_;
+    my $name   = blessed($source) ? $source->name : $source;
+    map join( '.', $name, $_ ), @names;
+  }
 
-  *body_cols = sub ($source) {
-    my %pk; @pk{$source->primary_columns} = ();
-    map +{ %{$source->column_info($_)}, name => $_ },
+  sub body_cols {
+    my $source = shift;
+    my %pk;
+    @pk{ $source->primary_columns } = ();
+    map +{ %{ $source->column_info($_) }, name => $_ },
       grep !exists $pk{$_}, $source->columns;
-  };
+  }
 
-  *pk_cols = sub ($source) {
-    map +{ %{$source->column_info($_)}, name => $_ },
+  sub pk_cols {
+    my $source = shift;
+    map +{ %{ $source->column_info($_) }, name => $_ },
       $source->primary_columns;
-  };
+  }
 
-  *names_of = sub (@cols) { map $_->{name}, @cols };
+  sub names_of { my @cols = @_; map $_->{name}, @cols }
 
-  *function_body = sub {
-    my ($name,$args,$body_parts) = @_;
-    my $arglist = join(
-      ', ',
-        map "_${\$_->{name}} ${\uc($_->{data_type})}",
-          @$args
-    );
-    my $body = join("\n", '', map "          $_;", @$body_parts);
+  sub function_body {
+    my ( $name, $args, $body_parts ) = @_;
+    my $arglist =
+      join( ', ', map "_${\$_->{name}} ${\uc($_->{data_type})}", @$args );
+    my $body = join( "\n", '', map "          $_;", @$body_parts );
     return strip tt q{
       CREATE OR REPLACE FUNCTION [% name %]
         ([% arglist %])
@@ -308,38 +295,21 @@ BEGIN {
         END;
       $function$ LANGUAGE plpgsql;
     };
-  };
-  #*function_body = sub ($name,$args,$body_parts) {
-    #my $arglist = join(
-      #', ',
-        #map "_${\$_->{name}} ${\uc($_->{data_type})}",
-          #@$args
-    #);
-    #my $body = join("\n", '', map "          $_;", @$body_parts);
-    #return strip tt q{
-      #CREATE OR REPLACE FUNCTION [% name %]
-        #([% arglist %])
-        #RETURNS VOID AS $function$
-        #BEGIN
-          #[%- body %]
-        #END;
-      #$function$ LANGUAGE plpgsql;
-    #};
-  #};
+  }
 }
 
 BEGIN {
 
-  use signatures;
-
-  *arg_hash = sub ($source) {
-    map +($_ => \(argify $_)), names_of body_cols $source;
-  };
+  sub arg_hash {
+    my $source = shift;
+    map +( $_ => \( argify $_) ), names_of body_cols $source;
+  }
 
-  *rule_body = sub ($on, $to, $oldlist, $newlist) {
-    my $arglist = join(', ',
-      (qualify_with 'OLD', names_of @$oldlist),
-      (qualify_with 'NEW', names_of @$newlist),
+  sub rule_body {
+    my ( $on, $to, $oldlist, $newlist ) = @_;
+    my $arglist = join( ', ',
+      ( qualify_with 'OLD', names_of @$oldlist ),
+      ( qualify_with 'NEW', names_of @$newlist ),
     );
     $to = $to->name if blessed($to);
     return strip tt q{
@@ -349,7 +319,7 @@ BEGIN {
           SELECT [% to %]_[% on %]([% arglist %])
         );
     };
-  };
+  }
 }
 
 method root_table () {
@@ -380,7 +350,7 @@ method view_definition () {
   my @pk_cols = pk_cols $self;
 
   # Grab sequence from root table. Only works with one PK named id...
-  # TBD: fix this so it's more flexible.
+  # TBD: Fix this so it's more flexible.
   for my $pk_col (@pk_cols) {
     $self->columns_info->{ $pk_col->{name} }->{sequence} =
       $self->root_table->name . '_id_seq';
@@ -481,7 +451,12 @@ Use multiple tables to define your classes
 
 =head1 NOTICE
 
-This only works with PostgreSQL for the moment.
+This only works with PostgreSQL at the moment. It has been tested with
+PostgreSQL 9.0, 9.1 beta, and 9.1.
+
+There is one additional caveat: the "parent" result classes that you
+defined with this resultsource must have one primary column and it must
+be named "id."
 
 =head1 SYNOPSIS