[Templates-cvs] cvs commit: TT3/lib/Template Context.pm
cvs@template-toolkit.org
cvs@template-toolkit.org
Wed, 01 Dec 2004 10:46:32 +0000
cvs 04/12/01 10:46:32
Modified: lib/Template Context.pm
Log:
* added the attach(), detach(), child() and parent() methods
Revision Changes Path
1.5 +68 -3 TT3/lib/Template/Context.pm
Index: Context.pm
===================================================================
RCS file: /template-toolkit/TT3/lib/Template/Context.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Context.pm 2004/11/24 16:22:40 1.4
+++ Context.pm 2004/12/01 10:46:32 1.5
@@ -16,7 +16,7 @@
# modify it under the same terms as Perl itself.
#
# REVISION
-# $Id: Context.pm,v 1.4 2004/11/24 16:22:40 abw Exp $
+# $Id: Context.pm,v 1.5 2004/12/01 10:46:32 abw Exp $
#
#========================================================================
@@ -35,7 +35,7 @@
use constant FETCH => 'fetch';
use constant GET => 'get';
-our $VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
+our $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
our $DEBUG = 0 unless defined $DEBUG;
our $ERROR = '';
our $THROW = 'context';
@@ -314,6 +314,71 @@
}
+#------------------------------------------------------------------------
+# attach($parent)
+#
+# Attach the current context to the parent context passed as an argument.
+#------------------------------------------------------------------------
+
+sub attach {
+ my ($self, $parent) = @_;
+
+ return $self->error('context is already attached to a parent')
+ if $self->{ parent };
+
+ $self->{ parent } = $parent;
+
+ # delete any cache of previously discovered resource locations
+ delete $self->{ locations };
+
+ return $self;
+}
+
+
+#------------------------------------------------------------------------
+# detach()
+#
+# Detach the current context from its parent.
+#------------------------------------------------------------------------
+
+sub detach {
+ my $self = shift;
+
+ # delete cache of previously discovered resource locations
+ delete $self->{ locations };
+
+ # delete parent and return reference to it
+ return delete $self->{ parent }
+ || $self->error('context is not attached to a parent')
+}
+
+
+#------------------------------------------------------------------------
+# child($config)
+#
+# Create a new context object and attach it to the current context.
+#------------------------------------------------------------------------
+
+sub child {
+ my $self = shift;
+ my $child = $self->new(@_) || return;
+ return $child->attach($self);
+}
+
+
+#------------------------------------------------------------------------
+# parent()
+#
+# Return the parent context.
+#------------------------------------------------------------------------
+
+sub parent {
+ my $self = shift;
+
+ return $self->{ parent }
+ || $self->error('context does not have a parent');
+}
+
@@ -401,7 +466,7 @@
=head1 VERSION
-$Revision: 1.4 $
+$Revision: 1.5 $
=head1 COPYRIGHT