start to sketch out code
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / lib / DBIx / Class / ResultSource / MultipleTableInheritance.pm
CommitLineData
876f6525 1package DBIx::Class::ResultSource::MultipleTableInheritance;
2
3use strict;
4use warnings;
5use parent qw(DBIx::Class::ResultSource::View);
6use namespace::autoclean;
7use Method::Signatures::Simple;
8use Carp::Clan qw/^DBIx::Class/;
70d56286 9
10# how this works:
11#
12# On construction, we hook $self->result_class->result_source_instance
13# if present to get the superclass' source object
14#
15# When attached to a schema, we need to add sources to that schema with
16# appropriate relationships for the foreign keys so the concrete tables
17# get generated
18#
19# We also generate our own view definition using this class' concrete table
20# and the view for the superclass, and stored procedures for the insert,
21# update and delete operations on this view.
22#
23# deploying the postgres rules through SQLT may be a pain though.
24
876f6525 25__PACKAGE__->mk_group_accessors(simple => qw(parent_source));
26
27method new ($class: @args) {
28 my $new = $class->next::method(@args);
29 my $rc = $new->result_class;
30 if (my $meth = $rc->can('result_source_instance')) {
31 $new->parent_source($rc->$meth);
32 }
33 if ($new->schema) {
34 $new->_attach_additional_sources;
35 }
36 return $new;
37}
38
39method _attach_additional_sources () {
40 my $raw_name = $self->_raw_source_name;
41}
42
43method _raw_source_name () {
44 my $base = $self->source_name;
45 confess "Can't generate raw source name when we don't have a source_name"
46 unless $base;
47 return 'Raw::'.$base;
48}
70d56286 49
876f6525 50method add_columns (@args) {
51 my $ret = $self->next::method(@args);
52 $_->{originally_defined_in} ||= $self->name for values %{$self->_columns};
53 return $ret;
70d56286 54}
55
561;