>>>>> "Stefano" == Stefano Rodighiero <[EMAIL PROTECTED]> writes:

Stefano>    package My::Package ;

Stefano>    our $my_scalar  = 'a scalar value' ;
Stefano>    our %my_hash = ( key=> 'value' ) ;
Stefano>    sub my_sub { ... }

What if you have

        our $my_data;
        our %my_data;

which one wins?

Stefano>   i. This mechanism is native in Template::Magic, so it was
Stefano>      natural to implement it in CGI::Builder::Magic too.
Stefano>      I don't know anything similar in TT. Does anyone?

You will have to create a third-parameter to ->process that
pulls all the scalars/arrays/hashes/functions from the current
package and builds a hash(ref).

Maybe something like:

    package MY::TEST;
    our $my_scalar = "this is my scalar";
    our @my_array = qw(this is my array);
    our %my_hash = qw(nit one perl two);
    sub my_code { print "hey there" };

    my %vars = Other::Package::gimme_my_vars();

    { package Other::Package;
      sub gimme_my_vars {
        no strict 'refs';
        my $pack_hash = caller() . "::";
        map {
          local *glob = $pack_hash->{$_};
          defined $glob ? ($_, $glob) :
          defined %glob ? ($_, \%glob) :
          defined @glob ? ($_, [EMAIL PROTECTED]) :
          defined &glob ? ($_, \&glob) : ()
        } keys %$pack_hash;
      }
    }

    require Data::Dumper;
    print Data::Dumper::Dumper(\%vars);

which prints:

    $VAR1 = {
              'my_code' => sub { "DUMMY" },
              'my_scalar' => 'this is my scalar',
              'my_array' => [
                              'this',
                              'is',
                              'my',
                              'array'
                            ],
              'my_hash' => {
                             'perl' => 'two',
                             'nit' => 'one'
                           }
            };

This shows that we've successfully captured all scalars, arrays,
hashes, and codes in the current package into %vars, which I could
then pass as a third arg to ->process.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to