__PACKAGE__->mk_group_accessors('simple' => qw/_ordered_columns
_columns _primaries _unique_constraints name resultset_attributes
- schema from _relationships column_info_from_storage source_name
- source_info/);
+ schema from _relationships column_info_from_storage source_info/);
__PACKAGE__->mk_group_accessors('inherited' => qw/resultset_class
result_class/);
+__PACKAGE__->mk_group_ro_accessors('simple' => qw/source_name/);
+
=head1 NAME
DBIx::Class::ResultSource - Result source object
use warnings;
use base qw/DBIx::Class/;
+use Scalar::Util qw/blessed/;
+use Carp::Clan qw/^DBIx::Class/;
sub iterator_class { shift->result_source_instance->resultset_class(@_) }
sub resultset_class { shift->result_source_instance->resultset_class(@_) }
sub result_class { shift->result_source_instance->result_class(@_) }
-sub source_name { shift->result_source_instance->source_name(@_) }
sub source_info { shift->result_source_instance->source_info(@_) }
+sub set_inherited_ro_instance {
+ my $self = shift;
+
+ croak "Cannot set @{[shift]} on an instance" if blessed $self;
+
+ return $self->set_inherited(@_);
+}
+
+sub get_inherited_ro_instance {
+ return shift->get_inherited(@_);
+}
+
+__PACKAGE__->mk_group_accessors('inherited_ro_instance' => 'source_name');
+
+
sub resultset_attributes {
shift->result_source_instance->resultset_attributes(@_);
}
sub register_source {
my ($self, $moniker, $source) = @_;
+
+ %$source = %{ $source->new( { %$source, source_name => $moniker }) };
+
my %reg = %{$self->source_registrations};
$reg{$moniker} = $source;
$self->source_registrations(\%reg);
+
$source->schema($self);
+
weaken($source->{schema}) if ref($self);
if ($source->result_class) {
my %map = %{$self->class_mappings};
}
}
+sub _unregister_source {
+ my ($self, $moniker) = @_;
+ my %reg = %{$self->source_registrations};
+
+ my $source = delete $reg{$moniker};
+ $self->source_registrations(\%reg);
+ if ($source->result_class) {
+ my %map = %{$self->class_mappings};
+ delete $map{$source->result_class};
+ $self->class_mappings(\%map);
+ }
+}
+
=head2 class
=over 4
}
}
$class->ensure_class_loaded($comp_class);
- $comp_class->source_name($comp) unless $comp_class->source_name;
- push(@to_register, [ $comp_class->source_name, $comp_class ]);
+ $comp = $comp_class->source_name || $comp;
+# $DB::single = 1;
+ push(@to_register, [ $comp, $comp_class ]);
}
}
}
cmp_ok(@artsn, '==', 4, "Four artists returned");
# make sure subclasses that don't set source_name are ok
- ok($schema->source('ArtistSubclass', 'ArtistSubclass exists'));
+ ok($schema->source('ArtistSubclass'), 'ArtistSubclass exists');
}
my $newbook = $schema->resultset( 'Bookmark' )->find(1);
use lib qw(t/lib);
use DBICTest;
-DBICTest::Schema::CD->add_column('year');
my $schema = DBICTest->init_schema();
+DBICTest::Schema::CD->add_column('year2');
+$DB::single = 1;
eval { require DateTime };
plan skip_all => "Need DateTime for inflation tests" if $@;
plan tests => 4;
-DBICTest::Schema::CD->inflate_column( 'year',
+$DB::single = 1;
+
+$schema->class('CD')
+#DBICTest::Schema::CD
+->inflate_column( 'year',
{ inflate => sub { DateTime->new( year => shift ) },
deflate => sub { shift->year } }
);