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

Diff of /nfo/perl/libs/Data/Rap/Context.pm

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

revision 1.1 by joko, Thu Feb 20 19:41:10 2003 UTC revision 1.2 by joko, Tue May 13 07:52:59 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.2  2003/05/13 07:52:59  joko
6    ##  enhanced: *hierarchical* containers for context handling
7    ##
8  ##  Revision 1.1  2003/02/20 19:41:10  joko  ##  Revision 1.1  2003/02/20 19:41:10  joko
9  ##  + initial commit  ##  + initial commit
10  ##  ##
# Line 20  use Data::Dumper; Line 23  use Data::Dumper;
23  sub setInstance {  sub setInstance {
24    my $self = shift;    my $self = shift;
25    my $instance = shift;    my $instance = shift;
26      # store reference to instance
27    $self->{__rap}->{context}->{instance} = $instance;    $self->{__rap}->{context}->{instance} = $instance;
28  }  }
29    
# Line 28  sub getInstance { Line 32  sub getInstance {
32    return $self->{__rap}->{context}->{instance};    return $self->{__rap}->{context}->{instance};
33  }  }
34    
35  sub setContainer {  sub __ctx_strip_args {
36    my $self = shift;    my $self = shift;
37    my $args = shift;    my $args = shift;
38      my $options = shift;
39      $options->{prefix} ||= '_';
40        
41    # strip all parameters prefixed by an underscore ('_')    # strip all parameters prefixed by an underscore ('_')
42      my $prefix = $options->{prefix};
43    foreach (keys %$args) {    foreach (keys %$args) {
44      delete $args->{$_} if m/^_/;      delete $args->{$_} if m/^$prefix/;
45    }    }
46      }
47    
48    sub setContainer_old {
49      my $self = shift;
50      my $args = shift;
51      $self->__ctx_strip_args($args);
52    $self->{__rap}->{context}->{container} = $args;    $self->{__rap}->{context}->{container} = $args;
53  }  }
54    
55  sub getContainer {  sub getContainer {
56    my $self = shift;    my $self = shift;
57    return $self->{__rap}->{context}->{container};    my $last = $#{$self->{__rap}->{context}->{container}};
58      return $self->{__rap}->{context}->{container}->[$last];
59    }
60    
61    sub clearContainer {
62      my $self = shift;
63      $self->{__rap}->{context}->{container} = {};
64    }
65    
66    sub __ctx_init_array {
67      my $self = shift;
68      if (ref $self->{__rap}->{context}->{container} ne 'ARRAY') {
69        $self->{__rap}->{context}->{container} = [ $self->{__rap}->{context}->{container} ];
70      }
71    }
72    
73    sub pushContainer {
74      my $self = shift;
75      my $args = shift;
76      $self->__ctx_init_array();
77      $self->__ctx_strip_args($args);
78      push @{$self->{__rap}->{context}->{container}}, $args;
79    }
80    
81    sub popContainer {
82      my $self = shift;
83      $self->__ctx_init_array();
84      pop @{$self->{__rap}->{context}->{container}};
85  }  }
86    
87  1;  1;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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