| 1 | #!/usr/bin/perl -w | ||
| 2 | package MOBY::simple_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::simple_input - a lightweight connection to the | ||
| 14 | simple_input table in the database | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | #NON FUNCTIONAL AT THIS TIME | ||
| 19 | |||
| 20 | use MOBY::simple_input; | ||
| 21 | my $Instance = MOBY::simple_input->new( | ||
| 22 | object_type => "Sequence", | ||
| 23 | namespaces => ["genbank/gi", "genbank/Acc"], | ||
| 24 | article_name => "InputSequenceThingy", | ||
| 25 | ); | ||
| 26 | print $Instance->simple_input_id; | ||
| 27 | print $Instance->service_instance_id; | ||
| 28 | |||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | =head1 DESCRIPTION | ||
| 33 | |||
| 34 | representation of the simple_input table. Can write to the database | ||
| 35 | |||
| 36 | =head1 AUTHORS | ||
| 37 | |||
| 38 | Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca) | ||
| 39 | |||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | { | ||
| 44 | |||
| 45 | # Encapsulated: | ||
| 46 | # DATA | ||
| 47 | #___________________________________________________________ | ||
| 48 | #ATTRIBUTES | ||
| 49 | my %_attr_data = # DEFAULT ACCESSIBILITY | ||
| 50 | ( | ||
| 51 | simple_input_id => [ undef, 'read/write' ], | ||
| 52 | object_type_uri => [ undef, 'read/write' ], | ||
| 53 | namespace_type_uris => [ undef, 'read/write' ], | ||
| 54 | article_name => [ undef, 'read/write' ], | ||
| 55 | service_instance_id => [ undef, 'read/write' ], | ||
| 56 | service_instance_lsid => [ undef, 'read/write' ], | ||
| 57 | collection_input_id => [ undef, 'read/write' ], | ||
| 58 | dbh => [ undef, 'read/write' ], | ||
| 59 | ); | ||
| 60 | |||
| 61 | #_____________________________________________________________ | ||
| 62 | # METHODS, to operate on encapsulated class data | ||
| 63 | # Is a specified object attribute accessible in a given mode | ||
| 64 | sub _accessible { | ||
| 65 | my ( $self, $attr, $mode ) = @_; | ||
| 66 | $_attr_data{$attr}[1] =~ /$mode/; | ||
| 67 | } | ||
| 68 | |||
| 69 | # Classwide default value for a specified object attribute | ||
| 70 | sub _default_for { | ||
| 71 | my ( $self, $attr ) = @_; | ||
| 72 | $_attr_data{$attr}[0]; | ||
| 73 | } | ||
| 74 | |||
| 75 | # List of names of all specified object attributes | ||
| 76 | sub _standard_keys { | ||
| 77 | keys %_attr_data; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | sub new { | ||
| 82 | my ( $caller, %args ) = @_; | ||
| 83 | my $caller_is_obj = ref($caller); | ||
| 84 | return $caller if $caller_is_obj; | ||
| 85 | my $class = $caller_is_obj || $caller; | ||
| 86 | my $proxy; | ||
| 87 | my $self = bless {}, $class; | ||
| 88 | foreach my $attrname ( $self->_standard_keys ) { | ||
| 89 | if ( exists $args{$attrname} ) { | ||
| 90 | $self->{$attrname} = $args{$attrname}; | ||
| 91 | } elsif ($caller_is_obj) { | ||
| 92 | $self->{$attrname} = $caller->{$attrname}; | ||
| 93 | } else { | ||
| 94 | $self->{$attrname} = $self->_default_for($attrname); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | my $id = $self->WRITE; | ||
| 98 | $self->simple_input_id($id) if defined $id; | ||
| 99 | return $self; | ||
| 100 | } | ||
| 101 | |||
| 102 | sub WRITE { | ||
| 103 | my ($self) = @_; | ||
| 104 | $CONFIG ||= MOBY::Config->new; # exported by Config.pm | ||
| 105 | my $adaptor = $CONFIG->getDataAdaptor( datasource => 'mobycentral' ); | ||
| 106 | my $id = $adaptor->insert_simple_input( | ||
| 107 | object_type_uri => $self->object_type_uri, | ||
| 108 | namespace_type_uris => $self->namespace_type_uris, | ||
| 109 | article_name => $self->article_name, | ||
| 110 | service_instance_lsid => $self->service_instance_lsid, | ||
| 111 | collection_input_id => $self->collection_input_id | ||
| 112 | ); | ||
| 113 | return $id; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub AUTOLOAD { | ||
| 117 | no strict "refs"; | ||
| 118 | my ( $self, $newval ) = @_; | ||
| 119 | $AUTOLOAD =~ /.*::(\w+)/; | ||
| 120 | my $attr = $1; | ||
| 121 | if ( $self->_accessible( $attr, 'write' ) ) { | ||
| 122 | *{$AUTOLOAD} = sub { | ||
| 123 | if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] } | ||
| 124 | return $_[0]->{$attr}; | ||
| 125 | }; ### end of created subroutine | ||
| 126 | ### this is called first time only | ||
| 127 | if ( defined $newval ) { | ||
| 128 | $self->{$attr} = $newval; | ||
| 129 | } | ||
| 130 | return $self->{$attr}; | ||
| 131 | } elsif ( $self->_accessible( $attr, 'read' ) ) { | ||
| 132 | *{$AUTOLOAD} = sub { | ||
| 133 | return $_[0]->{$attr}; | ||
| 134 | }; ### end of created subroutine | ||
| 135 | return $self->{$attr}; | ||
| 136 | } | ||
| 137 | |||
| 138 | # Must have been a mistake then... | ||
| 139 | croak "No such method: $AUTOLOAD"; | ||
| 140 | } | ||
| 141 | sub DESTROY { } | ||
| 142 | 1; |