| 1 | package Text::Template::LocalVars::Package; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Symbol qw[ delete_package ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Storable qw[ dclone ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | my $pkgid = 0; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =begin quiet_pod_coverage | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head2 new | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =end quiet_pod_coverage | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 12 | my ( $class, $orig ) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 12 | my $self = bless \( __PACKAGE__ . '::Q' . $pkgid++ ), $class; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 12 | $self->_copy_package( $orig ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 12 | return $self; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =begin quiet_pod_coverage | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 pkg | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =end quiet_pod_coverage | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 48 | ▶ | sub pkg { ${ $_[0] } } | ||||||||||||||||||||||||||
|
Subroutine
pkg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 12 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 12 | delete_package( $self->pkg ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 12 | return; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #<<< no perltidy | ||||||||||||||||||||||||||||
| 48 | # ignore dclone warnings; $Storable::forgive_me set below | ||||||||||||||||||||||||||||
| 49 | my @Map = ( | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | [ HASH => '%' => sub {local $SIG{__WARN__} = sub { }; dclone( shift );}], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | [ ARRAY => '@' => sub {local $SIG{__WARN__} = sub { }; dclone( shift );}], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | 309 | ▶ | [ CODE => '&' => sub { shift } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 21 | ▶ | [ SCALAR => '$' => sub { ${ $_[0] } if 'SCALAR' eq ref $_[0] } ], | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | #>>> no perltidy | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 12 | ▶ | sub _copy_package { | ||||||||||||||||||||||||||
|
Subroutine
_copy_package: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 12 | my ( $self, $src_pkg ) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | my $src = Package::Stash->new( $src_pkg ); | |||||||||||||||||||||||||||
| 62 | 12 | my $dst = Package::Stash->new( $self->pkg ); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # can't use the globs directly, but because scalar slots in | ||||||||||||||||||||||||||||
| 65 | # globs will always return a reference (at least as of Perl | ||||||||||||||||||||||||||||
| 66 | # 5.20.1) even if unused. that means we'd create extra scalars | ||||||||||||||||||||||||||||
| 67 | # where there were none. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # we don't care if dclone can't store things we don't care | ||||||||||||||||||||||||||||
| 70 | # about (like GLOBS buried in a hash or an array) | ||||||||||||||||||||||||||||
| 71 | 12 | local $Storable::forgive_me = 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 12 | for my $map ( @Map ) { | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 48 | my ( $type, $sigil, $convert ) = @$map; | |||||||||||||||||||||||||||
| 76 | 48 | my $symbols = $src->get_all_symbols( $type ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 48 | ▶ | while ( my ( $var, $value ) = each %$symbols ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # don't clone | ||||||||||||||||||||||||||||
| 81 | # * anything which looks like a package stash. | ||||||||||||||||||||||||||||
| 82 | # * the special _ variable, which causes things to segv | ||||||||||||||||||||||||||||
| 83 | # on some Perls when the package is deleted. | ||||||||||||||||||||||||||||
| 84 | 330 | ▶ | next if $var =~ /::$/ or $var eq '_'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$var =~ /::$/ or $var eq "_"
MC/DC0%0/2
$var =~ /::$/ or $var eq "_"
$var =~ /::$/
$var eq "_"
Truth table33%1/3
A or B
A= $var =~ /::$/B= $var eq "_"
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 330 | ▶ | eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 330 | $dst->add_symbol( $sigil . $var, $convert->( $value ) ); | |||||||||||||||||||||||||||
| 88 | 330 | 1; | |||||||||||||||||||||||||||
| 89 | } or die( "error adding $sigil$var: $@\n" ); | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | 1; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =head1 NAME | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Text::Template::LocalVars::Package - manage clone of a template variable package | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Don't do anything with this | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | This is a private module for use by L<Text::Template::LocalVars::Package>. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Diab Jerius, C<< <djerius at cpan.org> >> | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Copyright (C) 2014 Smithsonian Astrophysical Observatory | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Copyright (C) 2014 Diab Jerius | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Text::Template::LocalVars is free software: you can redistribute it | ||||||||||||||||||||||||||||
| 121 | and/or modify it under the terms of the GNU General Public License as | ||||||||||||||||||||||||||||
| 122 | published by the Free Software Foundation, either version 3 of the | ||||||||||||||||||||||||||||
| 123 | License, or (at your option) any later version. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 126 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 127 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 128 | GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 131 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||