Merge branch 'master' into topic/parent_string
[cxgn-corelibs.git] / lib / MOBY / collection_input.pm
blob0ebbc2a1aceccb0ee288b5c69f7b4ca270dd1c1e
1 package MOBY::collection_input;
2 use strict;
3 use Carp;
4 use MOBY::Config;
5 use vars qw($AUTOLOAD @ISA);
7 =head1 NAME
9 MOBY::collection_input - a lightweight connection to the
10 collection_input table in the database
12 =head1 SYNOPSIS
14 NON FUNCTIONAL AT THIS TIME
16 use MOBY::collection_input;
17 my $Instance = MOBY::collection_input->new(
18 object_type => "Sequence",
19 namespaces => ["genbank/gi", "genbank/Acc"],
20 article_name => "InputSequenceThingy",
25 =cut
27 =head1 DESCRIPTION
29 representation of the collection_input table. Can write to the database
31 =head1 AUTHORS
33 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
36 =cut
40 # Encapsulated:
41 # DATA
42 #___________________________________________________________
43 #ATTRIBUTES
44 my %_attr_data = # DEFAULT ACCESSIBILITY
46 collection_input_id => [ undef, 'read/write' ],
47 article_name => [ undef, 'read/write' ],
48 service_instance_id => [ undef, 'read/write' ],
49 service_instance_lsid => [ undef, 'read/write' ],
50 dbh => [ undef, 'read/write' ],
53 #_____________________________________________________________
54 # METHODS, to operate on encapsulated class data
55 # Is a specified object attribute accessible in a given mode
56 sub _accessible {
57 my ( $self, $attr, $mode ) = @_;
58 $_attr_data{$attr}[1] =~ /$mode/;
61 # Classwide default value for a specified object attribute
62 sub _default_for {
63 my ( $self, $attr ) = @_;
64 $_attr_data{$attr}[0];
67 # List of names of all specified object attributes
68 sub _standard_keys {
69 keys %_attr_data;
73 sub new {
74 my ( $caller, %args ) = @_;
75 my $caller_is_obj = ref($caller);
76 return $caller if $caller_is_obj;
77 my $class = $caller_is_obj || $caller;
78 my $proxy;
79 my $self = bless {}, $class;
80 foreach my $attrname ( $self->_standard_keys ) {
81 if ( exists $args{$attrname} ) {
82 $self->{$attrname} = $args{$attrname};
83 } elsif ($caller_is_obj) {
84 $self->{$attrname} = $caller->{$attrname};
85 } else {
86 $self->{$attrname} = $self->_default_for($attrname);
89 my $id = $self->WRITE;
90 $self->collection_input_id($id) if defined $id;
91 return $self;
94 sub WRITE {
95 my ($self) = @_;
96 $CONFIG ||= MOBY::Config->new; # exported by Config.pm
97 my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' );
98 my $id = $adaptor->insert_collection_input(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 { }