Bio-Chado-Schema
view release on metacpan or search on metacpan
lib/Bio/Chado/Schema.pm view on Meta::CPAN
Convenience method to for finding single cvterms based on the text
name of the CV and the term. The cvterm objects found with this
method are cached in the schema object itself. Thus, you only use
this function in the (relatively common) scenario in which you just
need convenient access to a handful of different cvterms.
=cut
sub get_cvterm {
my ( $self, $cv_name, $term_name ) = @_;
croak "must provide at least one argument!" unless @_ > 1;
unless( $term_name ) {
($cv_name, $term_name) = split /:/, $cv_name, 2;
}
return $self->{_bio_chado_schema_cvterm_cache}{$cv_name}{$term_name} ||=
$self->resultset('Cv::Cv')
->search({ 'me.name' => $cv_name })
->search_related('cvterms', { 'cvterms.name' => $term_name })
->single;
}
=head2 get_cvterm_or_die
Same as get_cvterm above, but dies with a "not found" message if the
cvterm is not found. This is convenient when you don't want to be
bothered with checking the return value of C<get_cvterm>, which for me
is most of the time.
=cut
sub get_cvterm_or_die {
shift->get_cvterm( @_ ) or croak "cvterm @_ not found";
}
=head1 CLASS METHODS
=head2 plugin_add_relationship( 'ChadoModule::SourceName', 'reltype', @args )
Sometimes application-specific plugins need to add relationships to
the core BCS classes. It can't just be done normally from inside the
classes of the plugins, you need to use this method.
Example: Bio::Chado::Schema::Result::MyApp::SpecialThing belongs_to
the core BCS Organism::Organism, and you would like to be able to call
C<$organism-E<gt>myapp_specialthings> on organisms to get their
associated SpecialThings.
package Bio::Chado::Schema::MyApp::Result::SpecialThing;
# ( do table and column definitions and so forth here )
Bio::Chado::Schema->plugin_add_relationship(
'Organism::Organism', 'has_many', (
"myapp_specialthings",
"Bio::Chado::Schema::MyApp::Result::Foo",
{ "foreign.organism_id" => "self.organism_id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
);
=cut
{
my @after_load;
$_->() for @after_load; #< note that this executes after load_classes above
sub plugin_add_relationship {
my ( $class, $target_moniker, $reltype, @args ) = @_;
push @after_load, sub {
no strict 'refs';
my $target_class = $class->class( $target_moniker );
$target_class->$reltype( @args );
__PACKAGE__->register_class( $target_moniker => $target_class );
};
}
}
sub DESTROY {
my $self = shift;
# need to delete our cvterm cache to avoid memory leaks
delete $self->{_bio_chado_schema_cvterm_cache};
$self->SUPER::DESTROY( @_ ) if $self->can( 'SUPER::DESTROY' );
}
=head1 AUTHOR
Robert Buels, <rmb32@cornell.edu>
=head1 CONTRIBUTORS
Naama Menda, <nm249@cornell.edu>
Aureliano Bombarely, <ab782@cornell.edu>
Jonathan "Duke" Leto, <jonathan@leto.net>
=cut
1;
( run in 0.978 second using v1.01-cache-2.11-cpan-524268b4103 )