| 1 | #$Id: DataAccessI.pm,v 1.3 2008/09/02 13:09:30 kawas Exp $ | ||
| 2 | # Write generic AUTOLOAD routines | ||
| 3 | package MOBY::Adaptor::moby::DataAccessI; | ||
| 4 | use strict; | ||
| 5 | use Carp; | ||
| 6 | |||
| 7 | use vars qw /$VERSION/; | ||
| 8 | $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | MOBY::Adaptor::moby::DataAccessI - This file may need to be renamed and may not make sense as | ||
| 13 | an interface. | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use MOBY::Adaptor::moby::queryapi::mysql # implements this interface def | ||
| 20 | my $m = MOBY::Adaptor::moby::queryapi::mysql->new( | ||
| 21 | username => 'user', | ||
| 22 | password => 'pass', | ||
| 23 | dbname => 'mobycentral', | ||
| 24 | port => '3306', | ||
| 25 | sourcetype => 'DBD::mysql'); | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | The BioMOBY registry data access interface | ||
| 32 | |||
| 33 | =head1 AUTHORS | ||
| 34 | |||
| 35 | Mark Wilkinson markw_at_ illuminae dot com | ||
| 36 | Dennis Wang oikisai _at_ hotmail dot com | ||
| 37 | BioMOBY Project: http://www.biomoby.org | ||
| 38 | |||
| 39 | |||
| 40 | =cut | ||
| 41 | |||
| 42 | =head1 METHODS | ||
| 43 | |||
| 44 | |||
| 45 | =head2 new | ||
| 46 | |||
| 47 | Usage : my $MOBY = MOBY::Client::Central->new(Registries => \%regrefs) | ||
| 48 | Function : connect to one or more MOBY-Central | ||
| 49 | registries for searching | ||
| 50 | Returns : MOBY::Client::Central object | ||
| 51 | Args : Registries - optional. | ||
| 52 | Notes : Each registry must have a different | ||
| 53 | |||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub new { | ||
| 58 | my ( $caller, %args ) = @_; | ||
| 59 | my $caller_is_obj = ref($caller); | ||
| 60 | my $class = $caller_is_obj || $caller; | ||
| 61 | |||
| 62 | my $self = bless {}, $class; | ||
| 63 | |||
| 64 | foreach my $attrname ( $self->_standard_keys_a ) { | ||
| 65 | if ( exists $args{$attrname} && defined $args{$attrname} ) { | ||
| 66 | $self->{$attrname} = $args{$attrname}; | ||
| 67 | } | ||
| 68 | elsif ($caller_is_obj) { | ||
| 69 | $self->{$attrname} = $caller->{$attrname}; | ||
| 70 | } | ||
| 71 | else { | ||
| 72 | $self->{$attrname} = $self->_default_for($attrname); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | return $self; | ||
| 76 | } | ||
| 77 | |||
| 78 | # Modified by Dennis | ||
| 79 | |||
| 80 | { | ||
| 81 | |||
| 82 | #Encapsulated class data | ||
| 83 | |||
| 84 | #___________________________________________________________ | ||
| 85 | #ATTRIBUTES | ||
| 86 | my %_attr_data = # DEFAULT ACCESSIBILITY | ||
| 87 | ( | ||
| 88 | username => [ undef, 'read/write' ], | ||
| 89 | password => [ undef, 'read/write' ], | ||
| 90 | dbname => [ undef, 'read/write' ], | ||
| 91 | port => [ undef, 'read/write' ], | ||
| 92 | proxy => [ undef, 'read/write' ], | ||
| 93 | url => [ undef, 'read/write' ], | ||
| 94 | driver => [ undef, 'read/write' ], | ||
| 95 | ); | ||
| 96 | |||
| 97 | #_____________________________________________________________ | ||
| 98 | |||
| 99 | # METHODS, to operate on encapsulated class data | ||
| 100 | |||
| 101 | # Is a specified object attribute accessible in a given mode | ||
| 102 | sub _accessible { | ||
| 103 | my ( $self, $attr, $mode ) = @_; | ||
| 104 | $_attr_data{$attr}[1] =~ /$mode/; | ||
| 105 | } | ||
| 106 | |||
| 107 | # Classwide default value for a specified object attribute | ||
| 108 | sub _default_for { | ||
| 109 | my ( $self, $attr ) = @_; | ||
| 110 | $_attr_data{$attr}[0]; | ||
| 111 | } | ||
| 112 | |||
| 113 | # List of names of all specified object attributes | ||
| 114 | sub _standard_keys_a { | ||
| 115 | keys %_attr_data; | ||
| 116 | } | ||
| 117 | |||
| 118 | =head2 username | ||
| 119 | |||
| 120 | Usage : my $un = $API->username($arg) | ||
| 121 | Function : get/set username (if required) | ||
| 122 | Returns : String (username) | ||
| 123 | Args : String (username) - optional. | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | sub username { | ||
| 128 | my ( $self, $arg ) = @_; | ||
| 129 | $self->{username} = $arg if defined $arg; | ||
| 130 | return $self->{username}; | ||
| 131 | } | ||
| 132 | |||
| 133 | =head2 password | ||
| 134 | |||
| 135 | Usage : my $un = $API->password($arg) | ||
| 136 | Function : get/set password (if required) | ||
| 137 | Returns : String (password) | ||
| 138 | Args : String (password) - optional. | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | sub password { | ||
| 143 | my ( $self, $arg ) = @_; | ||
| 144 | $self->{password} = $arg if defined $arg; | ||
| 145 | return $self->{password}; | ||
| 146 | } | ||
| 147 | |||
| 148 | =head2 dbname | ||
| 149 | |||
| 150 | Usage : my $un = $API->dbname($arg) | ||
| 151 | Function : get/set dbname (if required) | ||
| 152 | Returns : String (dbname) | ||
| 153 | Args : String (dbname) - optional. | ||
| 154 | |||
| 155 | =cut | ||
| 156 | |||
| 157 | sub dbname { | ||
| 158 | my ( $self, $arg ) = @_; | ||
| 159 | $self->{dbname} = $arg if defined $arg; | ||
| 160 | return $self->{dbname}; | ||
| 161 | } | ||
| 162 | |||
| 163 | =head2 port | ||
| 164 | |||
| 165 | Usage : my $un = $API->port($arg) | ||
| 166 | Function : get/set port (if required) | ||
| 167 | Returns : String (port) | ||
| 168 | Args : String (port) - optional. | ||
| 169 | |||
| 170 | =cut | ||
| 171 | |||
| 172 | sub port { | ||
| 173 | my ( $self, $arg ) = @_; | ||
| 174 | $self->{port} = $arg if defined $arg; | ||
| 175 | return $self->{port}; | ||
| 176 | } | ||
| 177 | |||
| 178 | =head2 proxy | ||
| 179 | |||
| 180 | Usage : my $un = $API->proxy($arg) | ||
| 181 | Function : get/set proxy (if required) | ||
| 182 | Returns : String (proxy) | ||
| 183 | Args : String (proxy) - optional. | ||
| 184 | |||
| 185 | =cut | ||
| 186 | |||
| 187 | sub proxy { | ||
| 188 | my ( $self, $arg ) = @_; | ||
| 189 | $self->{proxy} = $arg if defined $arg; | ||
| 190 | return $self->{proxy}; | ||
| 191 | } | ||
| 192 | |||
| 193 | =head2 sourcetype | ||
| 194 | |||
| 195 | Usage : my $un = $API->sourcetype($arg) | ||
| 196 | Function : get/set string name of sourcetype (e.g. mySQL) | ||
| 197 | Returns : String (sourcetype) | ||
| 198 | Args : String (sourcetype) - optional. | ||
| 199 | |||
| 200 | =cut | ||
| 201 | |||
| 202 | sub sourcetype { | ||
| 203 | my ( $self, $arg ) = @_; | ||
| 204 | $self->{sourcetype} = $arg if defined $arg; | ||
| 205 | return $self->{sourcetype}; | ||
| 206 | } | ||
| 207 | |||
| 208 | =head2 driver | ||
| 209 | |||
| 210 | Usage : my $un = $API->driver($arg) | ||
| 211 | Function : get/set string name of driver module (e.g. DBD::mySQL) | ||
| 212 | Returns : String (driver) | ||
| 213 | Args : String (driver) - optional. | ||
| 214 | |||
| 215 | =cut | ||
| 216 | |||
| 217 | sub driver { | ||
| 218 | my ( $self, $arg ) = @_; | ||
| 219 | $self->{driver} = $arg if defined $arg; | ||
| 220 | return $self->{driver}; | ||
| 221 | } | ||
| 222 | |||
| 223 | =head2 url | ||
| 224 | |||
| 225 | Usage : my $un = $API->url($arg) | ||
| 226 | Function : get/set url (if required) | ||
| 227 | Returns : String (url) | ||
| 228 | Args : String (url) - optional. | ||
| 229 | |||
| 230 | =cut | ||
| 231 | |||
| 232 | sub url { | ||
| 233 | my ( $self, $arg ) = @_; | ||
| 234 | $self->{url} = $arg if defined $arg; | ||
| 235 | return $self->{url}; | ||
| 236 | } | ||
| 237 | |||
| 238 | sub _implementation { | ||
| 239 | my ( $self, $arg ) = @_; | ||
| 240 | $self->{'_implementation'} = $arg if defined $arg; | ||
| 241 | return $self->{'_implementation'}; | ||
| 242 | } | ||
| 243 | |||
| 244 | =head2 dbh | ||
| 245 | |||
| 246 | Usage : my $un = $API->dbh($arg) | ||
| 247 | Function : get/set database handle (if required) | ||
| 248 | Returns : Database handle in whatever object is appropriate for sourcetype | ||
| 249 | Args : Database handle in whatever object is appropriate for sourcetype | ||
| 250 | |||
| 251 | =cut | ||
| 252 | |||
| 253 | sub dbh { | ||
| 254 | my ( $self, $arg ) = @_; | ||
| 255 | $self->{dbh} = $arg if defined $arg; | ||
| 256 | return $self->{dbh}; | ||
| 257 | } | ||
| 258 | |||
| 259 | } | ||
| 260 | |||
| 261 | sub DESTROY { } | ||
| 262 | |||
| 263 | 1; |