fixed recursive_children cvterm function, and added tests for parents and children
[cxgn-corelibs.git] / lib / MOBY / collection_output.pm
blob4c14a906500a12ad47cc4d20d3adc8479edc4274
1 #!/usr/bin/perl -w
2 package MOBY::collection_output;
3 use strict;
4 use Carp;
5 use MOBY::Config;
6 use vars qw($AUTOLOAD @ISA);
8 =head1 NAME
10 MOBY::collection_output - a lightweight connection to the
11 collection_output table in the database
13 =head1 SYNOPSIS
15 NON FUNCTIONAL AT THIS TIME
16 use MOBY::collection_output;
17 my $Instance = MOBY::collection_output->new(
18 object_type => "Sequence",
19 namespaces => ["genbank/gi", "genbank/Acc"],
20 article_name => "InputSequenceThingy",
24 =cut
26 =head1 DESCRIPTION
28 representation of the collection_output table. Can write to the database
30 =head1 AUTHORS
32 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
35 =cut
39 # Encapsulated:
40 # DATA
41 #___________________________________________________________
42 #ATTRIBUTES
43 my %_attr_data = # DEFAULT ACCESSIBILITY
45 collection_output_id => [ undef, 'read/write' ],
46 article_name => [ undef, 'read/write' ],
47 service_instance_id => [ undef, 'read/write' ],
48 service_instance_lsid => [ undef, 'read/write' ],
49 dbh => [ undef, 'read/write' ],
52 #_____________________________________________________________
53 # METHODS, to operate on encapsulated class data
54 # Is a specified object attribute accessible in a given mode
55 sub _accessible {
56 my ( $self, $attr, $mode ) = @_;
57 $_attr_data{$attr}[1] =~ /$mode/;
60 # Classwide default value for a specified object attribute
61 sub _default_for {
62 my ( $self, $attr ) = @_;
63 $_attr_data{$attr}[0];
66 # List of names of all specified object attributes
67 sub _standard_keys {
68 keys %_attr_data;
72 sub new {
73 my ( $caller, %args ) = @_;
74 my $caller_is_obj = ref($caller);
75 return $caller if $caller_is_obj;
76 my $class = $caller_is_obj || $caller;
77 my $proxy;
78 my $self = bless {}, $class;
79 foreach my $attrname ( $self->_standard_keys ) {
80 if ( exists $args{$attrname} ) {
81 $self->{$attrname} = $args{$attrname};
82 } elsif ($caller_is_obj) {
83 $self->{$attrname} = $caller->{$attrname};
84 } else {
85 $self->{$attrname} = $self->_default_for($attrname);
88 my $id = $self->WRITE;
89 $self->collection_output_id($id) if defined $id;
90 return $self;
93 sub WRITE {
94 my ($self) = @_;
95 $CONFIG ||= MOBY::Config->new; # exported by Config.pm
96 my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' );
97 my $id = $adaptor->insert_collection_output(
98 service_instance_lsid => $self->service_instance_lsid,
99 article_name => $self->article_name);
100 return $id;
103 sub AUTOLOAD {
104 no strict "refs";
105 my ( $self, $newval ) = @_;
106 $AUTOLOAD =~ /.*::(\w+)/;
107 my $attr = $1;
108 if ( $self->_accessible( $attr, 'write' ) ) {
109 *{$AUTOLOAD} = sub {
110 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
111 return $_[0]->{$attr};
112 }; ### end of created subroutine
113 ### this is called first time only
114 if ( defined $newval ) {
115 $self->{$attr} = $newval;
117 return $self->{$attr};
118 } elsif ( $self->_accessible( $attr, 'read' ) ) {
119 *{$AUTOLOAD} = sub {
120 return $_[0]->{$attr};
121 }; ### end of created subroutine
122 return $self->{$attr};
125 # Must have been a mistake then...
126 croak "No such method: $AUTOLOAD";
128 sub DESTROY { }