| 1 | package Text::MicroMason::AllowGlobals; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | ###################################################################### | ||||||||||||||
| 7 | |||||||||||||||
| 8 | 8 | ▶ | sub allow_globals { | ||||||||||||
|
Subroutine
allow_globals: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||
| 9 | 8 | my $self = shift; | |||||||||||||
| 10 | 8 | my $globals = $self->{allow_globals}; | |||||||||||||
| 11 | 8 | ▶ | my @current = ref( $globals ) ? @$globals : | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 12 | ! defined( $globals ) ? () : | ||||||||||||||
| 13 | split ' ' , $globals; | ||||||||||||||
| 14 | |||||||||||||||
| 15 | 8 | ▶ | if ( scalar @_ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 16 | 4 | my %once_each; | |||||||||||||
| 17 | 4 | @current = grep { ! ( $once_each{$_} ++ ) } @current, @_; | |||||||||||||
| 18 | 4 | $self->{allow_globals} = \@current; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 8 | ▶ | wantarray ? @current : join(' ', @current); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | ###################################################################### | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 1 | ▶ | sub set_globals { | ||||||||||||
|
Subroutine
set_globals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 27 | 1 | my ( $self, %globals ) = @_; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 1 | my @globals = keys %globals; | |||||||||||||
| 30 | 1 | $self->allow_globals( @globals ); | |||||||||||||
| 31 | |||||||||||||||
| 32 | my $sub = join( "\n", | ||||||||||||||
| 33 | $self->allow_globals_statement(), | ||||||||||||||
| 34 | " sub { ", | ||||||||||||||
| 35 | map( { | ||||||||||||||
| 36 | 1 | my $var = $_; $var =~ s/^[\@\%]/*/; $var =~ s/^(\w)/\$$1/; | |||||||||||||
| 37 | 1 | "$var = \$_[0]{'$_'};" | |||||||||||||
| 38 | } @globals ), | ||||||||||||||
| 39 | " }" | ||||||||||||||
| 40 | ); | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 1 | $self->eval_sub( $sub )->( \%globals ) | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | |||||||||||||||
| 45 | ###################################################################### | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 4 | ▶ | sub allow_globals_statement { | ||||||||||||
|
Subroutine
allow_globals_statement: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 48 | 4 | my $self = shift; | |||||||||||||
| 49 | 4 | "use vars qw(" . $self->allow_globals() . ");" | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 3 | ▶ | sub assemble { | ||||||||||||
|
Subroutine
assemble: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 53 | 3 | my $self = shift; | |||||||||||||
| 54 | 3 | $self->NEXT('assemble', once => $self->allow_globals_statement(), @_); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | |||||||||||||||
| 57 | ###################################################################### | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | 1; | |||||||||||||
| 60 | |||||||||||||||
| 61 | __END__ | ||||||||||||||