--- nfo/perl/libs/Data/Storage.pm 2002/10/29 19:24:18 1.5 +++ nfo/perl/libs/Data/Storage.pm 2002/11/17 06:07:18 1.7 @@ -1,4 +1,4 @@ -# $Id: Storage.pm,v 1.5 2002/10/29 19:24:18 joko Exp $ +# $Id: Storage.pm,v 1.7 2002/11/17 06:07:18 joko Exp $ # # Copyright (c) 2002 Andreas Motl # @@ -7,6 +7,13 @@ ################################# # # $Log: Storage.pm,v $ +# Revision 1.7 2002/11/17 06:07:18 joko +# + creating the handler is easier than proposed first - for now :-) +# + sub testAvailability +# +# Revision 1.6 2002/11/09 01:04:58 joko +# + updated pod +# # Revision 1.5 2002/10/29 19:24:18 joko # - reduced logging # + added some pod @@ -66,8 +73,17 @@ =head2 NOTE This module heavily relies on DBI and Tangram, but adds a lot of additional bugs and quirks. -Please look at their documentation and this code for additional information. +Please look at their documentation and/or this code for additional information. + + +=head1 REQUIREMENTS +For full functionality: + DBI from CPAN + Tangram from CPAN + Class::Tangram from CPAN + MySQL::Diff from http://adamspiers.org/computing/mysqldiff/ + ... and all their dependencies =cut @@ -80,7 +96,9 @@ use warnings; use Data::Storage::Locator; +use Data::Dumper; +# TODO: actually implement level (integrate with Log::Dispatch) my $TRACELEVEL = 0; # get logger instance @@ -90,13 +108,14 @@ my $invocant = shift; my $class = ref($invocant) || $invocant; #my @args = normalizeArgs(@_); - + my $arg_locator = shift; my $arg_options = shift; - + #my $self = { STORAGEHANDLE => undef, @_ }; my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; - $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + #$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); return bless $self, $class; } @@ -131,10 +150,12 @@ # e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" # but that would be way too specific as long as we don't have an abstract handler for this ;) $logger->debug( $logstring ); + #print join('; ', @_); } # filtering AUTOLOAD calls if ($self->_filter_AUTOLOAD($method)) { + #print "_accessStorage\n"; $self->_accessStorage(); $self->{STORAGEHANDLE}->$method(@_); } @@ -175,33 +196,27 @@ sub _createStorageHandle { my $self = shift; - my $type = $self->{locator}->{type}; $logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); my $pkg = "Data::Storage::Handler::" . $type . ""; - # propagate args to handler - # needs some more thoughts! (not only "dbi" to Tangram, when (in future) db is not more the common case) - if ($type eq 'DBI') { - use Data::Storage::Handler::DBI; - #my @args = %{$self->{locator}->{dbi}}; - my @args = %{$self->{locator}}; - # create new storage handle - $self->{STORAGEHANDLE} = $pkg->new( @args ); - } - if ($type eq 'Tangram') { - use Data::Storage::Handler::Tangram; - #$self->{STORAGEHANDLE} = $pkg->new( dsn => $self->{locator}->{dbi}->{dsn} ); - #my @args = %{$self->{locator}->{dbi}}; - my @args = %{$self->{locator}}; - # create new storage handle - $self->{STORAGEHANDLE} = $pkg->new( @args ); - - #$self->{STORAGEHANDLE_UNDERLYING} = $self->{STORAGEHANDLE}->getUnderlyingStorage(); - #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE(); + # try to load perl module at runtime + my $evalstr = "use $pkg;"; + eval($evalstr); + if ($@) { + $logger->error( __PACKAGE__ . "[$type]" . "->_createStorageHandle(): $@" ); + return; } + # build up some additional arguments to pass on + #my @args = %{$self->{locator}}; + my @args = (); + + # create new storage handle object, propagate arguments to handler + # pass locator by reference to be able to store status information in it + $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); + } sub addLogDispatchHandler { @@ -260,10 +275,17 @@ $dbh->disconnect(); return 1; } else { - $logger->error( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); + $logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); } } +sub testAvailability { + my $self = shift; + my $status = $self->testDsn(); + $self->{locator}->{status}->{available} = $status; + return $status; +} + sub createDb { my $self = shift; my $dsn = $self->{locator}->{dbi}->{dsn}; @@ -341,9 +363,8 @@ =head1 ACKNOWLEDGEMENTS -Larry Wall and the C for Perl, -Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object, -Sam Vilain for Class::Tangram. +Larry Wall for Perl, Tim Bunce for DBI, Jean-Louis Leroy for Tangram and Set::Object, +Sam Vilain for Class::Tangram, Adam Spiers for MySQL::Diff and all contributors. =head1 SUPPORT / WARRANTY @@ -434,6 +455,7 @@ (Dia (free): http://www.lysator.liu.se/~alla/dia/) UMLet (free, university): http://www.swt.tuwien.ac.at/umlet/index.html Voodoo (free): http://voodoo.sourceforge.net/ + Umbrello UML Modeller: http://uml.sourceforge.net/ UML Tools: http://www.objectsbydesign.com/tools/umltools_byPrice.html