| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Template::TAL::Language::PerlValue - use perl in TAL attributes | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | (in a template) | ||
| 8 | |||
| 9 | <hi tal:content="perl: `cat /etc/passwd`">title here</h1> | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | Loading this module as a language into your TAL parser will allow you to use | ||
| 14 | perl code in your attribute values. This is, of course, horribly dangerous. | ||
| 15 | The core of TAL is safe to expose to users - there are no core functions that | ||
| 16 | let a template damage your system. But loading PerlValue will let the writer | ||
| 17 | of the template perform arbitrary actions on your server as the user that is | ||
| 18 | running the perl process. You have access to all of perl from within your | ||
| 19 | attribute code. You can load modules, open files, delete things, send email, | ||
| 20 | whatever. | ||
| 21 | |||
| 22 | If you just want the ability to do simple computations in your templates I | ||
| 23 | suggest you look at Template::TAL::Language::JavaScript, which embeds a nicely | ||
| 24 | sandboxed JavaScript interpreter, and is much safer. | ||
| 25 | |||
| 26 | Assuming you're happy with this... | ||
| 27 | |||
| 28 | In your perl code, you will have access to a $context hashref, which is | ||
| 29 | the local TAL context. Altering this hash will change the context. | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | package Template::TAL::Language::PerlValue; | ||
| 34 | use warnings; | ||
| 35 | use strict; | ||
| 36 | use base qw( Template::TAL::Language ); | ||
| 37 | |||
| 38 | =over | ||
| 39 | |||
| 40 | =item process_tales_perl( path, contexts, plugins ) | ||
| 41 | |||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | sub process_tales_perl { | ||
| 46 | # use really weird variable names, to try to avoid clashing with things. | ||
| 47 | my ($___class, $___path, $___contexts, $___plugins) = @_; | ||
| 48 | my $context = { map(%$_, reverse @$___contexts) }; | ||
| 49 | my $___res = eval($___path); | ||
| 50 | die $@ if $@; | ||
| 51 | return $___res; | ||
| 52 | } | ||
| 53 | |||
| 54 | =back | ||
| 55 | |||
| 56 | =head1 COPYRIGHT | ||
| 57 | |||
| 58 | Written by Tom Insam, Copyright 2005 Fotango Ltd. All Rights Reserved | ||
| 59 | |||
| 60 | This program is free software; you can redistribute | ||
| 61 | it and/or modify it under the same terms as Perl itself. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | 1; |