--- nfo/perl/libs/Data/Rap/Context.pm 2003/02/20 19:41:10 1.1 +++ nfo/perl/libs/Data/Rap/Context.pm 2003/05/13 07:52:59 1.2 @@ -1,7 +1,10 @@ ## ---------------------------------------------------------------------- -## $Id: Context.pm,v 1.1 2003/02/20 19:41:10 joko Exp $ +## $Id: Context.pm,v 1.2 2003/05/13 07:52:59 joko Exp $ ## ---------------------------------------------------------------------- ## $Log: Context.pm,v $ +## Revision 1.2 2003/05/13 07:52:59 joko +## enhanced: *hierarchical* containers for context handling +## ## Revision 1.1 2003/02/20 19:41:10 joko ## + initial commit ## @@ -20,6 +23,7 @@ sub setInstance { my $self = shift; my $instance = shift; + # store reference to instance $self->{__rap}->{context}->{instance} = $instance; } @@ -28,21 +32,56 @@ return $self->{__rap}->{context}->{instance}; } -sub setContainer { +sub __ctx_strip_args { my $self = shift; my $args = shift; + my $options = shift; + $options->{prefix} ||= '_'; # strip all parameters prefixed by an underscore ('_') + my $prefix = $options->{prefix}; foreach (keys %$args) { - delete $args->{$_} if m/^_/; + delete $args->{$_} if m/^$prefix/; } - +} + +sub setContainer_old { + my $self = shift; + my $args = shift; + $self->__ctx_strip_args($args); $self->{__rap}->{context}->{container} = $args; } sub getContainer { my $self = shift; - return $self->{__rap}->{context}->{container}; + my $last = $#{$self->{__rap}->{context}->{container}}; + return $self->{__rap}->{context}->{container}->[$last]; +} + +sub clearContainer { + my $self = shift; + $self->{__rap}->{context}->{container} = {}; +} + +sub __ctx_init_array { + my $self = shift; + if (ref $self->{__rap}->{context}->{container} ne 'ARRAY') { + $self->{__rap}->{context}->{container} = [ $self->{__rap}->{context}->{container} ]; + } +} + +sub pushContainer { + my $self = shift; + my $args = shift; + $self->__ctx_init_array(); + $self->__ctx_strip_args($args); + push @{$self->{__rap}->{context}->{container}}, $args; +} + +sub popContainer { + my $self = shift; + $self->__ctx_init_array(); + pop @{$self->{__rap}->{context}->{container}}; } 1;