X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FModel%2FDBIC%2FSchema.pm;h=ab367721c7ffb904817ec285d6af291de0f6e649;hb=46a2eb0ca8128a8a2a6ac06b18d1a33d747d1d33;hp=cfdb5e4ce1bcc1d9fa659b418ace0de362918fb7;hpb=18b829f093f42145aa14e6f52faa1faeb6e8e695;p=catagits%2FCatalyst-Model-DBIC-Schema.git diff --git a/lib/Catalyst/Model/DBIC/Schema.pm b/lib/Catalyst/Model/DBIC/Schema.pm index cfdb5e4..ab36772 100644 --- a/lib/Catalyst/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Model/DBIC/Schema.pm @@ -5,13 +5,14 @@ use mro 'c3'; extends 'Catalyst::Model'; with 'CatalystX::Component::Traits'; -our $VERSION = '0.25'; +our $VERSION = '0.26'; use namespace::autoclean; use Carp::Clan '^Catalyst::Model::DBIC::Schema'; use Data::Dumper; use DBIx::Class (); use Moose::Autobox; +use Class::Inspector (); use Catalyst::Model::DBIC::Schema::Types qw/ConnectInfo LoadedClass/; @@ -384,6 +385,15 @@ Traits you used resolved to full class names. =head1 METHODS +Methods not listed here are delegated to the connected schema used by the model +instance, so the following are equivalent: + + $c->model('DB')->schema->my_accessor('foo'); + # or + $c->model('DB')->my_accessor('foo'); + +Methods on the model take precedence over schema methods. + =head2 new Instantiates the Model based on the above-documented ->config parameters. @@ -431,8 +441,6 @@ Used often for debugging and controlling transactions. =cut -has schema => (is => 'rw', isa => 'DBIx::Class::Schema'); - has schema_class => ( is => 'ro', isa => LoadedClass, @@ -451,6 +459,13 @@ has model_name => ( lazy_build => 1, ); +# method names delegated to schema +has _delegates => ( + is => 'ro', + isa => ArrayRef, + lazy_build => 1 +); + has _default_cursor_class => ( is => 'ro', isa => LoadedClass, @@ -485,6 +500,12 @@ sub BUILD { $self->composed_schema($schema_class->compose_namespace($class)); + $self->meta->add_attribute('schema', + is => 'rw', + isa => $self->schema_class, + handles => $self->_delegates + ); + $self->schema($self->composed_schema->clone); $self->schema->storage_type($self->storage_type) @@ -499,10 +520,6 @@ sub clone { shift->composed_schema->clone(@_); } sub connect { shift->composed_schema->connect(@_); } -sub storage { shift->schema->storage(@_); } - -sub resultset { shift->schema->resultset(@_); } - =head2 setup Called at C> time before configuration, but after L is @@ -573,6 +590,24 @@ sub _build_model_name { return $model_name; } +sub _build__delegates { + my $self = shift; + +# XXX change this to CMOP once CAG is updated + my @schema_methods = @{ Class::Inspector->methods($self->schema_class) }; + + my @my_methods = $self->meta->get_all_method_names; + my %my_methods; + @my_methods{@my_methods} = (); + + my @delegates; + for my $method (@schema_methods) { + push @delegates, $method unless exists $my_methods{$method}; + } + + return \@delegates; +} + __PACKAGE__->meta->make_immutable; =head1 SEE ALSO