| 1 | #!/usr/bin/perl -w | ||
| 2 | package MOBY::secondary_input; | ||
| 3 | use strict; | ||
| 4 | use Carp; | ||
| 5 | use MOBY::Config; | ||
| 6 | use vars qw($AUTOLOAD @ISA); | ||
| 7 | |||
| 8 | use vars qw /$VERSION/; | ||
| 9 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | MOBY::secondary_input - a lightweight connection to the | ||
| 14 | secondary_input table in the database | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | NON FUNCTIONAL AT THIS TIME | ||
| 19 | |||
| 20 | use MOBY::secondary_input; | ||
| 21 | |||
| 22 | my $Instance = MOBY::secondary_input->new( | ||
| 23 | object_type => "Sequence", | ||
| 24 | namespaces => ["genbank/gi", "genbank/Acc"], | ||
| 25 | article_name => "InputSequenceThingy", | ||
| 26 | ); | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | =head1 DESCRIPTION | ||
| 31 | |||
| 32 | representation of the secondary_input table. Can write to the database | ||
| 33 | |||
| 34 | =head1 AUTHORS | ||
| 35 | |||
| 36 | Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca) | ||
| 37 | |||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | { | ||
| 42 | |||
| 43 | # Encapsulated: | ||
| 44 | # DATA | ||
| 45 | #___________________________________________________________ | ||
| 46 | #ATTRIBUTES | ||
| 47 | my %_attr_data = # DEFAULT ACCESSIBILITY | ||
| 48 | ( | ||
| 49 | secondary_input_id => [ undef, 'read/write' ], | ||
| 50 | default_value => [ undef, 'read/write' ], | ||
| 51 | maximum_value => [ undef, 'read/write' ], | ||
| 52 | minimum_value => [ undef, 'read/write' ], | ||
| 53 | enum_value => [ undef, 'read/write' ], | ||
| 54 | datatype => [ undef, 'read/write' ], | ||
| 55 | article_name => [ undef, 'read/write' ], | ||
| 56 | service_instance_id => [ undef, 'read/write' ], | ||
| 57 | service_instance_lsid => [ undef, 'read/write' ], | ||
| 58 | dbh => [ undef, 'read/write' ], | ||
| 59 | description => [ undef, 'read/write' ], | ||
| 60 | ); | ||
| 61 | |||
| 62 | #_____________________________________________________________ | ||
| 63 | # METHODS, to operate on encapsulated class data | ||
| 64 | # Is a specified object attribute accessible in a given mode | ||
| 65 | sub _accessible { | ||
| 66 | my ( $self, $attr, $mode ) = @_; | ||
| 67 | $_attr_data{$attr}[1] =~ /$mode/; | ||
| 68 | } | ||
| 69 | |||
| 70 | # Classwide default value for a specified object attribute | ||
| 71 | sub _default_for { | ||
| 72 | my ( $self, $attr ) = @_; | ||
| 73 | $_attr_data{$attr}[0]; | ||
| 74 | } | ||
| 75 | |||
| 76 | # List of names of all specified object attributes | ||
| 77 | sub _standard_keys { | ||
| 78 | keys %_attr_data; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | # I hope this is cruft now...?? | ||
| 83 | #sub _dbh { | ||
| 84 | # my ($self) = @_; | ||
| 85 | # my $central_connect = MOBY::central_db_connection->new(); | ||
| 86 | # $self->dbh( $central_connect->dbh ); | ||
| 87 | # return $central_connect->dbh; | ||
| 88 | #} | ||
| 89 | |||
| 90 | sub new { | ||
| 91 | my ( $caller, %args ) = @_; | ||
| 92 | my $caller_is_obj = ref($caller); | ||
| 93 | return $caller if $caller_is_obj; | ||
| 94 | my $class = $caller_is_obj || $caller; | ||
| 95 | my $proxy; | ||
| 96 | my $self = bless {}, $class; | ||
| 97 | foreach my $attrname ( $self->_standard_keys ) { | ||
| 98 | if ( exists $args{$attrname} ) { | ||
| 99 | $self->{$attrname} = $args{$attrname}; | ||
| 100 | } elsif ($caller_is_obj) { | ||
| 101 | $self->{$attrname} = $caller->{$attrname}; | ||
| 102 | } else { | ||
| 103 | $self->{$attrname} = $self->_default_for($attrname); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | my $datatype = $self->datatype; | ||
| 107 | unless ( ( $datatype =~ /Integer/ ) | ||
| 108 | || ( $datatype =~ /Float/ ) | ||
| 109 | || ( $datatype =~ /String/ ) | ||
| 110 | || ( $datatype =~ /Boolean/ ) | ||
| 111 | || ( $datatype =~ /DateTime/ ) ) | ||
| 112 | { | ||
| 113 | return undef; | ||
| 114 | } | ||
| 115 | my $id = $self->WRITE; | ||
| 116 | $self->secondary_input_id($id) if defined $id; | ||
| 117 | return $self; | ||
| 118 | } | ||
| 119 | |||
| 120 | sub WRITE { | ||
| 121 | my ($self) = @_; | ||
| 122 | $CONFIG ||= MOBY::Config->new; # exported by Config.pm | ||
| 123 | my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' ); | ||
| 124 | my $dbh = $self->dbh; | ||
| 125 | my $insertid = $adaptor->insert_secondary_input( | ||
| 126 | default_value => $self->default_value, | ||
| 127 | maximum_value => $self->maximum_value, | ||
| 128 | minimum_value => $self->minimum_value, | ||
| 129 | enum_value => $self->enum_value, | ||
| 130 | datatype => $self->datatype, | ||
| 131 | article_name => $self->article_name, | ||
| 132 | service_instance_lsid => $self->service_instance_lsid, | ||
| 133 | description => $self->description | ||
| 134 | ); | ||
| 135 | |||
| 136 | return $insertid; | ||
| 137 | } | ||
| 138 | |||
| 139 | sub AUTOLOAD { | ||
| 140 | no strict "refs"; | ||
| 141 | my ( $self, $newval ) = @_; | ||
| 142 | $AUTOLOAD =~ /.*::(\w+)/; | ||
| 143 | my $attr = $1; | ||
| 144 | if ( $self->_accessible( $attr, 'write' ) ) { | ||
| 145 | *{$AUTOLOAD} = sub { | ||
| 146 | if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] } | ||
| 147 | return $_[0]->{$attr}; | ||
| 148 | }; ### end of created subroutine | ||
| 149 | ### this is called first time only | ||
| 150 | if ( defined $newval ) { | ||
| 151 | $self->{$attr} = $newval; | ||
| 152 | } | ||
| 153 | return $self->{$attr}; | ||
| 154 | } elsif ( $self->_accessible( $attr, 'read' ) ) { | ||
| 155 | *{$AUTOLOAD} = sub { | ||
| 156 | return $_[0]->{$attr}; | ||
| 157 | }; ### end of created subroutine | ||
| 158 | return $self->{$attr}; | ||
| 159 | } | ||
| 160 | |||
| 161 | # Must have been a mistake then... | ||
| 162 | croak "No such method: $AUTOLOAD"; | ||
| 163 | } | ||
| 164 | sub DESTROY { } | ||
| 165 | 1; |