1 # Copyright 2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: local.coretag,v 1.2 2007-08-09 13:40:52 pajamian Exp $
10 UserTag local Order scratch
11 UserTag local attrAlias scratches scratch
12 UserTag local attrAlias value values
13 UserTag local posNumber 1
14 UserTag local hasEndTag
16 UserTag local Description Tag to localize scratch and/or values for block
17 UserTag local Routine <<EOR
19 my ($scratch, $opt, $body) = @_;
21 use Storable qw/ dclone /;
22 $Storable::forgive_me = 1;
24 ## It may seem simpler just to clone the top-level reference and
25 ## be done with it, but we are going through all these gyrations
26 ## to prevent the problem of overwriting code, which is not
27 ## preserved with a cloning operation.
29 ## Obviously (or maybe not) if you pass a top-level array which
30 ## happens to contain a code reference, you are going to lose it.
31 ## But code references which are in non-localized hash keys will
38 # Perhaps {extra} is a bad option, but it has to be something. We
39 # don't have the _ intro for a key, alas. Doubt it will often be
40 # used, but discounts could be localized, I suppose.
42 my @extra = split /[,\s\0]+/, $opt->{extra};
44 for my $top (qw/ values scratch /, @extra) {
46 exists $Vend::Session->{$top}
48 $delete_top{$top} = 1;
52 my $v = $Vend::Session->{$top};
54 unless (ref($v) eq 'HASH') {
59 $settings{$top} = dclone($v);
64 my @values = Text::ParseWords::shellwords($opt->{$top});
67 if( ! exists $v->{$_}) {
68 $delete{$top}{$_} = 1;
70 elsif(! ref $v->{$_}) {
71 $settings{$top}{$_} = $v->{$_};
74 $settings{$top}{$_} = dclone($v->{$_});
79 my $result = interpolate_html($body);
81 for my $top (qw/ values scratch /, @extra) {
82 if(my $d = $delete_top{$top}) {
83 delete $Vend::Session->{$top};
87 unless (ref($settings{$top}) eq 'HASH') {
88 $Vend::Session->{$top} = $settings{$top};
92 my $s = $settings{$top};
93 my $d = $delete{$top};
94 my $v = $Vend::Session->{$top};
101 $v->{$_} = $settings{$top}{$_};
110 UserTag local Documentation <<EOT
113 local -- localize scratch, values, etc. for code block.
119 [local scratch="foo"]
120 [set foo]nonbar[/set]
124 [if scratch foo eq bar]
127 local did not work, kept at [scratch foo].
133 The local tag allows you to drop some code using scratch or values settings
134 in a page without the possibility of affecting the overall operation of the