1 package MOBY
::central_db_connection
;
4 use vars
qw($AUTOLOAD @ISA);
9 MOBY::central_db_connection - container object for a specific DB connection
13 use MOBY::simple_output;
14 my $dbh = MOBY::central_db_connection->new(
15 db_connect_object => "MOBY::mysql",
16 username => "myusername"
17 password => "mypassword",
23 $sth = $dbh->prepare("select * from tablename");
30 representation of the authority table. Can write to the database
34 Mark Wilkinson (mwilkinson@gene.pbi.nrc.ca)
43 #___________________________________________________________
45 my %_attr_data = # DEFAULT ACCESSIBILITY
47 db_connect_object => [ "MOBY::mysql", 'read/write' ],
48 datasource => [ 'mobycentral', 'read/write' ],
50 #username => ["mobycentral", 'read/write'],
51 #password => ["mobycentral", 'read/write'],
52 #dbname => ["mobycentral", 'read/write'],
53 #host => ["localhost", 'read/write'],
54 #port => [3306, 'read/write'],
55 dbh => [ undef, 'read/write' ],
58 #_____________________________________________________________
59 # METHODS, to operate on encapsulated class data
60 # Is a specified object attribute accessible in a given mode
62 my ( $self, $attr, $mode ) = @_;
63 $_attr_data{$attr}[1] =~ /$mode/;
66 # Classwide default value for a specified object attribute
68 my ( $self, $attr ) = @_;
69 $_attr_data{$attr}[0];
72 # List of names of all specified object attributes
77 sub db_connect_object {
78 my ( $self, $attr ) = @_;
79 $self->{db_connect_object} = $attr if defined $attr;
80 return $self->{db_connect_object};
84 my ( $self, $attr ) = @_;
85 $self->{dbh} = $attr if defined $attr;
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;
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};
103 $self->{$attrname} = $self->_default_for($attrname);
106 $CONFIG ||= MOBY::Config->new;
108 # getting the dbh is bad bad bad!!!
109 my $dbh = $CONFIG->getDataAdaptor( datasource => 'mobycentral' )->dbh;
116 my ( $self, $newval ) = @_;
117 $AUTOLOAD =~ /.*::(\w+)/;
119 if ( $self->_accessible( $attr, 'write' ) ) {
121 if ( defined $_[1] ) { $_[0]->{$attr} = $_[1] }
122 return $_[0]->{$attr};
123 }; ### end of created subroutine
124 ### this is called first time only
125 if ( defined $newval ) {
126 $self->{$attr} = $newval;
128 return $self->{$attr};
129 } elsif ( $self->_accessible( $attr, 'read' ) ) {
131 return $_[0]->{$attr};
132 }; ### end of created subroutine
133 return $self->{$attr};
136 # Must have been a mistake then...
137 croak "No such method: $AUTOLOAD";