aherzog: Adam Herzog <adam@herzogdesigns.com>
+amiri: Amiri Barksdale <amiri@metalabel.com>
+
amoore: Andrew Moore <amoore@cpan.org>
andyg: Andy Grundman <andy@hybridized.org>
'simple' => qw(is_virtual view_definition depends_on)
);
-sub new {
- my $new = shift->next::method(@_);
- $new->{depends_on} = { %{$new->{depends_on}||{}} };
- return $new;
-}
-
=head1 NAME
DBIx::Class::ResultSource::View - ResultSource object representing a view
An SQL query for your view. Will not be translated across database
syntaxes.
-
=head1 OVERRIDDEN METHODS
+=head2 new
+
+The constructor. This is a private method, as only other DBIC modules
+should call this. See L<DBIx::Class::ResultSource::MultipleTableInheritance>.
+
+=cut
+
+sub new {
+ my $new = shift->next::method(@_);
+ $new->{depends_on} = { %{$new->{depends_on}||{}} };
+ return $new;
+}
+
=head2 from
Returns the FROM entry for the table (i.e. the view name)
return $self->name;
}
+=head1 PRIVATE METHODS
+
+=head2 depends_on
+
+An internal method for the construction of a hashref of the view's
+superclasses, e.g., the sources that comprise it.
+
+See L<DBIx::Class::ResultSource::MultipleTableInheritance>.
+
+=cut
+
1;
=head1 AUTHORS
<=>
(exists $b->depends_on->{$a->source_name} ? 1 : 0)
}
- map { $dbicschema->source($_) } (sort keys %@view_monikers);
+ map { $dbicschema->source($_) } (sort keys %view_monikers);
foreach my $source (@view_sources)
{
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use Devel::Dwarn;
+use ViewDeps;
+
+BEGIN {
+ use_ok('DBIx::Class::ResultSource::View');
+}
+
+my $view = DBIx::Class::ResultSource::View->new( { name => 'Upsilon' } );
+isa_ok( $view, 'DBIx::Class::ResultSource' );
+isa_ok( $view, 'DBIx::Class' );
+
+can_ok( $view, $_ ) for qw/new from depends_on/;
+
+diag( map {"$_\n"} @{ mro::get_linear_isa($view) } );
+#diag( DwarnS $view);
+
+my $schema = ViewDeps->connect;
+ok($schema);
+
+#diag(DwarnS $schema);
+
+#diag(DwarnS $schema->resultset('Bar')->result_source->depends_on);
+diag keys %{$schema->resultset('Bar')->result_source->depends_on};
+my @dependencies = keys %{$schema->resultset('Bar')->result_source->depends_on};
+is($dependencies[0], 'mixin');
+
+done_testing;
--- /dev/null
+package # hide from PAUSE
+ ViewDeps;
+
+use strict;
+use warnings;
+use parent qw(DBIx::Class::Schema);
+use aliased 'DBIx::Class::ResultSource::View' => 'View';
+
+__PACKAGE__->load_namespaces;
+
+#for my $p (__PACKAGE__) {
+ #$p->load_namespaces;
+ #$_->attach_additional_sources
+ #for grep $_->isa(View), map $p->source($_), $p->sources;
+#}
+
+1;
--- /dev/null
+package # hide from PAUSE
+ ViewDeps::Result::Bar;
+
+use strict;
+use warnings;
+use parent qw(ViewDeps::Result::Foo);
+
+require ViewDeps::Result::Mixin;
+
+__PACKAGE__->table('bar');
+
+__PACKAGE__->result_source_instance->depends_on(
+ { ViewDeps::Result::Mixin->result_source_instance->name => 1 }
+);
+
+__PACKAGE__->add_columns(
+ b => { data_type => 'integer' }
+);
+
+__PACKAGE__->belongs_to(
+ 'b_thang',
+ 'ViewDeps::Result::JustATable',
+ { 'foreign.id' => 'self.b' },
+);
+
+__PACKAGE__->has_many(
+ 'foos',
+ 'ViewDeps::Result::Foo',
+ { 'foreign.a' => 'self.id' }
+);
+
+1;
--- /dev/null
+package # hide from PAUSE
+ ViewDeps::Result::Foo;
+
+use strict;
+use warnings;
+use parent qw(DBIx::Class::Core);
+use aliased 'DBIx::Class::ResultSource::View';
+
+__PACKAGE__->table_class(View);
+
+__PACKAGE__->table('foo');
+
+__PACKAGE__->add_columns(
+ id => { data_type => 'integer', is_auto_increment => 1 },
+ a => { data_type => 'integer', is_nullable => 1 }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->belongs_to(
+ 'bar',
+ 'ViewDeps::Result::Bar',
+ { 'foreign.id' => 'self.a' }
+);
+
+1;
--- /dev/null
+package # hide from PAUSE
+ ViewDeps::Result::JustATable;
+
+use base qw(DBIx::Class::Core);
+
+__PACKAGE__->table('just_a_table');
+
+__PACKAGE__->add_columns(
+ id => { data_type => 'integer', is_auto_increment => 1 },
+ name => { data_type => 'varchar', size => 255 }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+__PACKAGE__->has_many(
+ 'bars',
+ 'ViewDeps::Result::Bar',
+ { 'foreign.b' => 'self.id' }
+);
+
+
+1;
--- /dev/null
+package # hide from PAUSE
+ ViewDeps::Result::Mixin;
+
+use strict;
+use warnings;
+use parent qw(DBIx::Class::Core);
+
+__PACKAGE__->table('mixin');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'integer', is_auto_increment => 1, sequence => 'foo_id_seq'
+ },
+ words => { data_type => 'text' }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;