/usr/share/perl5/Text/MicroMason/PassVariables.pm is in libtext-micromason-perl 2.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | package Text::MicroMason::PassVariables;
use strict;
######################################################################
my $seqno = 0;
sub prepare {
my $self = shift;
$self->NEXT('prepare', @_,
( $self->{package} ? () : ( package => __PACKAGE__ . '::GEN' . $seqno++ ) )
)
}
######################################################################
# Text elements used for subroutine assembly
sub assembler_rules {
my %rules = ((shift)->NEXT('assembler_rules', @_),
eval_start => 'package __PACKAGE__;',
no_strict => 'no strict;',
init_args => 'local %__PACKAGE__:: = %__PACKAGE__::;' . "\n" .
'my %ARGS = @_;' . "\n" .
'$m->install_args_hash( "__PACKAGE__", \%ARGS );',
);
$rules{template} = ['$eval_start', '$no_strict', @{$rules{template}}];
return %rules;
}
sub assemble {
my $self = shift;
my $code = $self->NEXT('assemble', @_);
my $package = $self->{package} || 'Text::MicroMason::Commands';
$code =~ s/(\S)__PACKAGE__/$1$package/g;
$code =~ s/__PACKAGE__(\S)/$package$1/g;
return $code;
}
######################################################################
# $mason->install_args_hash( $package, $hash_ref )
sub install_args_hash {
my ($self, $dest, $hash) = @_;
foreach my $name (keys %$hash) {
my $val = $hash->{$name};
my $sym = $dest . "::" . $name;
no strict 'refs';
# This code is cloned from Text::Template
local *SYM = *{$sym};
if (! defined $val) {
delete ${"${dest}::"}{$name};
} elsif (ref $val) {
*SYM = $val;
} else {
*SYM = \$val;
}
}
}
######################################################################
1;
__END__
######################################################################
=head1 NAME
Text::MicroMason::PassVariables - Pass template data as variables
=head1 SYNOPSIS
Instead of using this class directly, pass its name to be mixed in:
use Text::MicroMason;
my $mason = Text::MicroMason->new( -PassVariables );
Use the standard compile and execute methods to parse and evalute templates:
print $mason->compile( text=>$template )->( 'name'=>'Dave' );
print $mason->execute( text=>$template, 'name'=>'Dave' );
Templates can now access their arguments as global variables:
Welcome, <% $name %>!
=head1 DESCRIPTION
Like Text::Template, this package passes in template arguments as package
variables. For example, if you pass in an argument list of C<foo =E<gt> 23>,
it will set the variable $foo in the package your template is compiled in.
This allows template code to refer to $name rather than $ARGS{name}.
The strict pragma is disabled to facilitate these variable references.
B<Caution:> Please note that this approach has some drawbacks, including the
risk of clobbering global variables used for other purposes. It is included
primarily to allow the TextTemplate module to emulate the behavior of
Text::Template, and for quick-and-dirty simple templates where succinctness
is more important than robustness.
=head2 Supported Attributes
=over 4
=item package
Target package namespace. Defaults to Text::MicroMason::Commands.
=back
=head2 Private Methods
=over 4
=item assembler_rules()
Adds Perl fragments to handle package and symbol table munging.
=item assemble()
Modifies Perl subroutine to embed the target package namespace.
=item install_args_hash()
Performs symbol table munging to transfer the contents of an arguments hash
into variables in a target namespace.
=back
=head1 SEE ALSO
The interface being emulated is described in L<Text::Template>.
For an overview of this templating framework, see L<Text::MicroMason>.
This is a mixin class intended for use with L<Text::MicroMason::Base>.
For distribution, installation, support, copyright and license
information, see L<Text::MicroMason::Docs::ReadMe>.
=cut
|