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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Tue May 13 07:52:59 2003 UTC (21 years, 1 month ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +45 -6 lines
enhanced: *hierarchical* containers for context handling

1 ## ----------------------------------------------------------------------
2 ## $Id: Context.pm,v 1.1 2003/02/20 19:41:10 joko Exp $
3 ## ----------------------------------------------------------------------
4 ## $Log: Context.pm,v $
5 ## Revision 1.1 2003/02/20 19:41:10 joko
6 ## + initial commit
7 ##
8 ## ----------------------------------------------------------------------
9
10
11 package Data::Rap::Context;
12
13 use strict;
14 use warnings;
15
16
17 use Data::Dumper;
18
19
20 sub setInstance {
21 my $self = shift;
22 my $instance = shift;
23 # store reference to instance
24 $self->{__rap}->{context}->{instance} = $instance;
25 }
26
27 sub getInstance {
28 my $self = shift;
29 return $self->{__rap}->{context}->{instance};
30 }
31
32 sub __ctx_strip_args {
33 my $self = shift;
34 my $args = shift;
35 my $options = shift;
36 $options->{prefix} ||= '_';
37
38 # strip all parameters prefixed by an underscore ('_')
39 my $prefix = $options->{prefix};
40 foreach (keys %$args) {
41 delete $args->{$_} if m/^$prefix/;
42 }
43 }
44
45 sub setContainer_old {
46 my $self = shift;
47 my $args = shift;
48 $self->__ctx_strip_args($args);
49 $self->{__rap}->{context}->{container} = $args;
50 }
51
52 sub getContainer {
53 my $self = shift;
54 my $last = $#{$self->{__rap}->{context}->{container}};
55 return $self->{__rap}->{context}->{container}->[$last];
56 }
57
58 sub clearContainer {
59 my $self = shift;
60 $self->{__rap}->{context}->{container} = {};
61 }
62
63 sub __ctx_init_array {
64 my $self = shift;
65 if (ref $self->{__rap}->{context}->{container} ne 'ARRAY') {
66 $self->{__rap}->{context}->{container} = [ $self->{__rap}->{context}->{container} ];
67 }
68 }
69
70 sub pushContainer {
71 my $self = shift;
72 my $args = shift;
73 $self->__ctx_init_array();
74 $self->__ctx_strip_args($args);
75 push @{$self->{__rap}->{context}->{container}}, $args;
76 }
77
78 sub popContainer {
79 my $self = shift;
80 $self->__ctx_init_array();
81 pop @{$self->{__rap}->{context}->{container}};
82 }
83
84 1;
85 __END__

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