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

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

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

revision 1.9 by joko, Thu Dec 19 16:30:23 2002 UTC revision 1.12 by joko, Thu Jan 30 21:46:32 2003 UTC
# Line 1  Line 1 
1  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
2  ##    $Id$  ##    $Id$
3  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
4  ##    $Log$  ##    $Log$
5    ##    Revision 1.12  2003/01/30 21:46:32  joko
6    ##    + fixed behaviour of AUTOLOAD-method
7    ##
8    ##    Revision 1.11  2003/01/20 16:43:18  joko
9    ##    + better argument-property merging
10    ##    + debugging-output !!!
11    ##    + abstract-dummy 'sub createChildNode'
12    ##
13    ##    Revision 1.10  2003/01/19 02:31:51  joko
14    ##    + fix to 'sub AUTOLOAD'
15    ##
16  ##    Revision 1.9  2002/12/19 16:30:23  joko  ##    Revision 1.9  2002/12/19 16:30:23  joko
17  ##    + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers  ##    + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers
18  ##  ##
# Line 30  Line 41 
41  ##  ##
42  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:07  cvsjoko
43  ##    + new  ##    + new
44  ##    --------------------------------------------------------------------------------  ##    ------------------------------------------------------------------------
45    
46    
47  package Data::Storage::Handler::Abstract;  package Data::Storage::Handler::Abstract;
# Line 40  use warnings; Line 51  use warnings;
51    
52  use base qw( DesignPattern::Object );  use base qw( DesignPattern::Object );
53    
54    
55  use Data::Dumper;  use Data::Dumper;
56  use Tie::SecureHash;  use Tie::SecureHash;
57  #use Data::Storage::Handler;  #use Data::Storage::Handler;
58    use Data::Transform::Deep qw( merge );
59    
60    
61  # get logger instance  # get logger instance
62  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 65  sub new { Line 79  sub new {
79    bless $self, $class;    bless $self, $class;
80  =cut  =cut
81    
82    #=pod
83    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...    # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash...
84    my $self = Tie::SecureHash->new(    my $self = Tie::SecureHash->new(
85      $class,      $class,
# Line 89  sub new { Line 103  sub new {
103        #_protected => ,        #_protected => ,
104        #__private => ,        #__private => ,
105    );    );
106    #=cut
107    
108    # merge passed-in arguments to constructor as properties into already blessed secure object    # merge passed-in arguments to constructor as properties into already blessed secure object
109        
110      # mungle arguments from array into hash - perl does the job  ;)      # mungle arguments from array into hash - perl does the job  ;)
111      my %args = @_;      #my %args = @_;
112          #my %args = ();
113    
114    #print Dumper(@_);
115    
116      # merge attributes one-by-one      # merge attributes one-by-one
117      # TODO: deep_copy? / merge_deep?      # TODO: deep_copy? / merge_deep?
118      foreach (keys %args) {      while (my $elemName = shift @_) {
119        #print "key: $_", "\n";        #print "elemName: $elemName", "\n";
120        $self->{$_} = $args{$_};        if (my $elemValue = shift @_) {
121            #print Dumper($elemValue);
122            #print "elemName=$elemName, elemValue=$elemValue", "\n";
123            $self->{$elemName} = $elemValue;
124          }
125          #$self->{$_} = $args{$_};
126          #$self->{$_} = $args{$_};
127      }      }
128        
129    # V3 - rolling our own security (just for {COREHANDLE} - nothing else)  -  nope, Tie::SecureHash works wonderful    # V3 - rolling our own security (just for {COREHANDLE} - nothing else)  -  nope, Tie::SecureHash works wonderful
# Line 124  sub new { Line 147  sub new {
147  }  }
148    
149    
150    # TODO: use NEXT.pm inside this mechanism (to avoid repetitions...)
151  sub AUTOLOAD {  sub AUTOLOAD {
152    
153    # recursion problem to be avoided here!!!    # recursion problem to be avoided here!!!
# Line 160  sub AUTOLOAD { Line 184  sub AUTOLOAD {
184    #if (!$self->exists('COREHANDLE')) { return; }    #if (!$self->exists('COREHANDLE')) { return; }
185    
186    # handle locking (hack)    # handle locking (hack)
187    if ($self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {    if ($self->can('exists') && $self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) {
188      $self->{lock_info}->{log_lock} = 1;      $self->{lock_info}->{log_lock} = 1;
189    } else {    } else {
190      $self->{lock_info}->{log_lock} = 0;      $self->{lock_info}->{log_lock} = 0;
# Line 181  sub AUTOLOAD { Line 205  sub AUTOLOAD {
205    #if (!$self->exists('_COREHANDLE')) {    #if (!$self->exists('_COREHANDLE')) {
206    #if (!$self->{_COREHANDLE}) {    #if (!$self->{_COREHANDLE}) {
207    if (!$core) {    if (!$core) {
208      my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";  
209  print $err_msg_core, "\n";  #print Dumper($self);    
210      if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {  #exit;
211    
212        my $handlertype = $self->{metainfo}->{type};
213        $handlertype ||= '';
214    
215        my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"";
216    
217    #print $err_msg_core, "\n";
218    
219        #if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) {
220        $logger->error( $err_msg_core );        $logger->error( $err_msg_core );
221      }      #}
222    
223      return;      return;
224        
225    }    }
226  #=cut  #=cut
227    
# Line 227  print $err_msg_core, "\n"; Line 262  print $err_msg_core, "\n";
262            
263  #print "calling: $methodname", "\n";  #print "calling: $methodname", "\n";
264            
265      # method calls doing it until here will get dispatched to the proper handler      # method calls making it until here will get dispatched to the proper handler
266      return $core->$methodname(@_);      return $core->$methodname(@_);
267        
268    } elsif ($self->can($methodname)) {    } elsif ($self->can($methodname)) {
269        # try to call specified method inside our or inherited module(s) scope(s)
270      return $self->$methodname(@_);      return $self->$methodname(@_);
271    }    }
272    
# Line 267  sub _typeCheck2 { Line 303  sub _typeCheck2 {
303      my $self = shift;      my $self = shift;
304      my $nodename = shift;      my $nodename = shift;
305      #$nodename = 'TransactionRoutingTable';      #$nodename = 'TransactionRoutingTable';
306      $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );      $logger->debug( __PACKAGE__ . "->existsChildNode( nodename $nodename )" );
307      $self->getChildNodes() unless $self->{meta}->{childnodes};      $self->getChildNodes() unless $self->{meta}->{childnodes};
308      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!      my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}});     # TODO: use "/i" only on win32-systems!
309      return $result;      return $result;
# Line 304  sub _typeCheck2 { Line 340  sub _typeCheck2 {
340      $self->_abstract_function('sendCommand');      $self->_abstract_function('sendCommand');
341    }    }
342    
343      sub createChildNode {
344        my $self = shift;
345        $self->_abstract_function('createChildNode');
346      }
347    
348    sub existsChildNode_tmp {    sub existsChildNode_tmp {
349      my $self = shift;      my $self = shift;
350      $self->_abstract_function('existsChildNode');      $self->_abstract_function('existsChildNode');

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.12

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