/[cvs]/nfo/perl/libs/Data/Storage.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by joko, Sun Jan 19 03:12:59 2003 UTC revision 1.16 by joko, Mon Jan 20 16:52:13 2003 UTC
# Line 9  Line 9 
9  ## ------------------------------------------------------------------------  ## ------------------------------------------------------------------------
10  ##  ##
11  ##  $Log$  ##  $Log$
12    ##  Revision 1.16  2003/01/20 16:52:13  joko
13    ##  + now using 'DesignPattern::Object' to create a new 'Data::Storage::Handler::Xyz' on demand - before we did this in a hand-rolled fashion
14    ##
15  ##  Revision 1.15  2003/01/19 03:12:59  joko  ##  Revision 1.15  2003/01/19 03:12:59  joko
16  ##  + modified header  ##  + modified header
17  ##  - removed pod-documentation - now in 'Storage.pod'  ##  - removed pod-documentation - now in 'Storage.pod'
# Line 81  package Data::Storage; Line 84  package Data::Storage;
84  use strict;  use strict;
85  use warnings;  use warnings;
86    
 use Data::Storage::Locator;  
87  use Data::Dumper;  use Data::Dumper;
88    # FIXME: wipe out!
 # TODO: wipe out!  
89  use DBI;  use DBI;
90    
91    use Data::Storage::Locator;
92    use DesignPattern::Object;
93    
94    
95  # TODO: actually implement level (integrate with Log::Dispatch)  # TODO: actually implement level (integrate with Log::Dispatch)
96  my $TRACELEVEL = 0;  my $TRACELEVEL = 0;
97    
# Line 133  sub AUTOLOAD { Line 138  sub AUTOLOAD {
138    
139    # advanced logging of AUTOLOAD calls ...    # advanced logging of AUTOLOAD calls ...
140    # ... nice but do it only when TRACING (TODO) is enabled    # ... nice but do it only when TRACING (TODO) is enabled
     if ($TRACELEVEL) {  
141        my $logstring = "";        my $logstring = "";
142        $logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method;        $logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method;
143        #print "count: ", $#_, "\n";        #print "count: ", $#_, "\n";
# Line 143  sub AUTOLOAD { Line 147  sub AUTOLOAD {
147        # TODO: only ok if logstring doesn't contain        # TODO: only ok if logstring doesn't contain
148        #            e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c))          (AUTOLOAD)"        #            e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c))          (AUTOLOAD)"
149        # but that would be _way_ too specific as long as we don't have an abstract handler for this  ;)        # but that would be _way_ too specific as long as we don't have an abstract handler for this  ;)
150        if ($TRACELEVEL) {
151        $logger->debug( $logstring );        $logger->debug( $logstring );
152        #print join('; ', @_);        #print join('; ', @_);
153      }      }
154            
155    # filtering AUTOLOAD calls and first-time-touch of the actual storage impl    # filtering AUTOLOAD calls and first-time-touch of the actual storage impl
156    if ($self->_filter_AUTOLOAD($method)) {    if ($self->_filter_AUTOLOAD($method)) {
     #print "_accessStorage\n";  
157      $self->_accessStorage();      $self->_accessStorage();
158      return $self->{STORAGEHANDLE}->$method(@_);      if ($self->{STORAGEHANDLE}) {
159          return $self->{STORAGEHANDLE}->$method(@_);
160        } else {
161          $logger->critical( __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring );
162          return;
163        }
164    }    }
165        
166  }  }
# Line 184  sub _accessStorage { Line 193  sub _accessStorage {
193      $logger->debug( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->_accessStorage()" );      $logger->debug( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->_accessStorage()" );
194    }    }
195    if (!$self->{STORAGEHANDLE}) {    if (!$self->{STORAGEHANDLE}) {
196      $self->_createStorageHandle();      return $self->_createStorageHandle();
197      }
198    }
199    
200    sub _createStorageHandle1 {
201      my $self = shift;
202      my $type = $self->{locator}->{type};
203      $logger->debug( __PACKAGE__ .  "[$type]" . "->_createStorageHandle()" );
204    
205      my $pkg = "Data::Storage::Handler::" . $type . "";
206      
207      # try to load perl module at runtime
208      my $evalstr = "use $pkg;";
209      eval($evalstr);
210      if ($@) {
211        $logger->error( __PACKAGE__ .  "[$type]" . "->_createStorageHandle(): $@" );
212        return;
213    }    }
214      
215      # build up some additional arguments to pass on
216      #my @args = %{$self->{locator}};
217      my @args = ();
218    
219      # - create new storage handle object
220      # - propagate arguments to handler
221      # - pass locator by reference to be able to store status- or meta-information in it
222      $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args );
223    
224  }  }
225    
226  sub _createStorageHandle {  sub _createStorageHandle {
# Line 193  sub _createStorageHandle { Line 228  sub _createStorageHandle {
228    my $type = $self->{locator}->{type};    my $type = $self->{locator}->{type};
229    $logger->debug( __PACKAGE__ .  "[$type]" . "->_createStorageHandle()" );    $logger->debug( __PACKAGE__ .  "[$type]" . "->_createStorageHandle()" );
230    
231    #print Dumper($self);
232    #exit;
233    
234    my $pkg = "Data::Storage::Handler::" . $type . "";    my $pkg = "Data::Storage::Handler::" . $type . "";
235        
236    # try to load perl module at runtime    # try to load perl module at runtime
237    =pod
238    my $evalstr = "use $pkg;";    my $evalstr = "use $pkg;";
239    eval($evalstr);    eval($evalstr);
240    if ($@) {    if ($@) {
# Line 211  sub _createStorageHandle { Line 250  sub _createStorageHandle {
250    # - propagate arguments to handler    # - propagate arguments to handler
251    # - pass locator by reference to be able to store status- or meta-information in it    # - pass locator by reference to be able to store status- or meta-information in it
252    $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args );    $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args );
253    =cut
254    
255      $self->{STORAGEHANDLE} = DesignPattern::Object->fromPackage( $pkg, locator => $self->{locator} );
256      return 1;
257    
258  }  }
259    
# Line 249  sub removeLogDispatchHandler { Line 292  sub removeLogDispatchHandler {
292    $logger->remove($name);    $logger->remove($name);
293  }  }
294    
295    =pod
296  sub getDbName {  sub getDbName {
297    my $self = shift;    my $self = shift;
298    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
# Line 286  sub testDsn { Line 330  sub testDsn {
330      $logger->warning( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );      $logger->warning( __PACKAGE__ .  "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr );
331    }    }
332  }  }
333    =cut
334    
335  1;  1;
336  __END__  __END__

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed