| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | Exporter::VA - Improved Exporter featuring Versioning and Aliasing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ### see the main POD at the end of this file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package Exporter::VA; | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION= v1.3.0.1; # major.minor.update.docsonly | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | *VERBOSE= *STDERR{IO}; # can be redirected | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my %EXPORT= ( | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | '&VERSION' => \&export_VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | '&import' => \&export_import, | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | '&AUTOLOAD' => \&export_AUTOLOAD, | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | '.default_VERSION'=> v0.1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ':normal' => [qw/ &VERSION &import &AUTOLOAD/ ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | '.&begin' => \&begin, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | '&normalize_vstring' => \\&normalize_vstring, | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | '&autoload_symbol' => \\&autoload_symbol, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sub Err | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Err: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # improve this to give proper level information to Croak. | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | croak @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | sub Warn | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | carp @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | sub dump | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Currently implemented to use Data::Dumper, but might change to be more custom some day. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | eval { require Data::Dumper }; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | print VERBOSE "**(Exporter::VA::dump) ERROR: cannot load Data::Dumper module to support the dump() method or --dump pragma\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | print VERBOSE (Data::Dumper->Dump ( [ $self ], ["*EXPORT"]), $/); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | sub is_vstring($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 45 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_vstring: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 45 | my $s= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 45 | my $count= $s =~ tr/\0-\1F//; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 45 | return $count > 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | # to disambiguate a v-string like v65.66.67, add a trailing .0 becoming v.65.66.67.0 with same meaning. | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub normalize_vstring ($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 40 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_vstring: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 40 | my $v= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | # for now, doesn't do much. | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 40 | ▶ | return v0 if length ($v) eq 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 39 | ▶ | $v= pack ("U*", split (/\./,$v)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | unless is_vstring ($v); | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # remove trailing redundant zeros (but keep it at least 2 digits, so v1.0 is right, v1.0.0.0 is truncated) | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 39 | $v =~ s/(?<=..)\0+$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 39 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | sub _calling_client() | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calling_client: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 24 | my $n= 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 24 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 28 | my $caller= caller($n); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 28 | ▶ | return $caller if $caller ne __PACKAGE__; # I want the first caller of this module | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | ++$n; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | sub _check_allowed_versions | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_allowed_versions: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my ($version, $list)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | return unless defined $list; # if .allowed_VERSIONS is not specified, anything is allowed. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | foreach (@$list) { | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | return if $version eq $_; # normalized earlier. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # compose error message | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $vs= join( ', ', map { _format_vstring($_)} (@$list) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | Err "(Exporter::VA) you asked for ", _format_vstring($version), ", but the only allowed versions are $vs"; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | sub generate_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_VERSION: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | my $export_def= shift; # might not have been blessed yet. | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | return sub { # this becomes the VERSION function in the exporting module. | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | my ($home, $version, $client)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | ▶ | $client= _calling_client() unless defined $client; # allow as optional argument | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 12 | ▶ | if (defined $version) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # assure correct version / set desired version | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | $version= normalize_vstring($version); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | Err "The version for this module has already been specified for module $client as ", _format_vstring ($export_def->{'..client_default_version'}{$client}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | if exists $export_def->{'..client_default_version'}{$client}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | ▶ | my $max_version= $export_def->{'..max_VERSION'} || _get_VERSION ($home); # first time, called before setup. | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$export_def->{'..max_VERSION'} || _get_VERSION($home)
MC/DC0%0/2
$export_def->{'..max_VERSION'} || _get_VERSION($home)
$export_def->{'..max_VERSION'}
_get_VERSION($home)
Truth table66%2/3
A || B
A= $export_def->{'..max_VERSION'}B= _get_VERSION($home)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | Err "$client requested version ", _format_vstring ($version), " but module $home is only version ", _format_vstring ($max_version) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | if $version gt $max_version; | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | _check_allowed_versions ($version, $export_def->{'.allowed_VERSIONS'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | $export_def->{'..client_default_version'}{$client}= $version; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # fetch version | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | return $export_def->{'..client_default_version'}{$client} if exists $export_def->{'..client_default_version'}{$client}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # never explicitly specified, so use the module's actual current version. | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $version= $export_def->{'..max_VERSION'} || _get_VERSION ($home); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$export_def->{'..max_VERSION'} || _get_VERSION($home)
MC/DC0%0/2
$export_def->{'..max_VERSION'} || _get_VERSION($home)
$export_def->{'..max_VERSION'}
_get_VERSION($home)
Truth table33%1/3
A || B
A= $export_def->{'..max_VERSION'}B= _get_VERSION($home)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $export_def->{'..client_default_version'}{$client}= $version; # once I decide, must always use the same result. | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return $version; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | sub get_import_version | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_import_version: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | my ($self, $client)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 13 | ▶ | unless (exists ($self->{'..client_default_version'}{$client})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | Err "(Exporter::VA) you must specify a version to import, since the module has no default." | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | unless exists $$self{'.default_VERSION'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | $self->{'..client_default_version'}{$client}= $$self{'.default_VERSION'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | print VERBOSE "(Exporter::VA) import version not specified, using .default_VERSION\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | ▶ | if $$self{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | return $$self{'..client_default_version'}{$client}; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub _format_vstring($) | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_vstring: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | return sprintf ("v%vd", shift); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub _normalize_vstring_list | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_vstring_list: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $list= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | for (my $loop= 0; $loop < @$list; $loop+=2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | normalize_vstring ($$list[$loop]); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | bless $list, "ARRAY-seen"; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | sub _match_vstring_list | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_vstring_list: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 7 | my ($list, $desired_version)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | # list is [ v1, item1, v2, item2, v3, item3, ... , vn, itemn ] | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # match $desired_version between two v's, and return (v,item). | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 7 | ▶ | for (my $index=0; $index < scalar(@$list); $index+=2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 17 | my $ver_at_index= $$list[$index]; # >> might need to normalize it. | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 17 | ▶ | next unless ($ver_at_index ge $desired_version); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # I get here when I found or passed my spot. | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | return @$list[$index, $index+1] if ($ver_at_index eq $desired_version); # found it exactly | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # otherwise I passed it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | ▶ | return (undef, undef, "desired version not found") if $index == 0; # before the first, is not present. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | return @$list[$index-2, $index-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # after the last, take the last. Should cap at Module's version, but that was checked earlier when VERSION was called. | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | return @$list[-2,-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub generate_import | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_import: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | my $export_def= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 13 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 13 | my $home= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 13 | $export_def->setup ($home); # happens first time used. | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | 13 | my $client= _calling_client(); | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 13 | my $version= $export_def->get_import_version ($client); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 13 | $export_def->callback ('.&begin', $client, $version, '.&begin', \@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | ▶ | @_ = ':DEFAULT' if (!@_ && defined $export_def->{':DEFAULT'}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @_ and defined $export_def->{":DEFAULT"}
MC/DC100%2/2
not @_ and defined $export_def->{":DEFAULT"}
not @_
defined $export_def->{":DEFAULT"}
Truth table100%3/3
not(A) and B
A= not @_B= defined $export_def->{":DEFAULT"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 13 | $export_def -> export ($client, $version, \@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 13 | $export_def->callback ('.&end', $client, $version, '.&begin', \@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 13 | $export_def->_process_worklist(); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 13 | ▶ | --$$export_def{'.verbose_import'} if $$export_def{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | sub export | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export: called CC=11 SCAR=27.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 18 | my ($self, $module, $version, $items)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | ▶ | $items= [$items] unless ref $items eq 'ARRAY'; # allow single item | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 18 | ▶ | while (my $item= shift @$items) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 40 | my $verbose= $$self{'.verbose_import'}; # must check object each time, not cache it. | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 40 | ▶ | print VERBOSE "(Exporter::VA) ===processing import parameter ($item)===\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 40 | ▶ | if (ref $item) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | print VERBOSE "(Exporter::VA) It's not a scalar, so invoking .&unknown_type callback. It's out of my hands.\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->callback ('.&unknown_type', $module, $version, $item, $items); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 40 | ▶ | if ($item =~ /^[\$\@\%\*\&]?\w+$/ or $item =~ /^-/ or $item =~s /^(<\w+)>$/$1/) { $self->export_one_symbol ($module,$version,$item,$items) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
$item =~ /^[\$\@\%\*\&]?\w+$/ or $item =~ /^-/ or $item =~ s/^(<\w+)>$/$1/
$item =~ /^[\$\@\%\*\&]?\w+$/ or $item =~ /^-/
MC/DC66%2/3
$item =~ /^[\$\@\%\*\&]?\w+$/ or $item =~ /^-/ or $item =~ s/^(<\w+)>$/$1/
$item =~ /^[\$\@\%\*\&]?\w+$/
$item =~ /^-/
$item =~ s/^(<\w+)>$/$1/
Truth table75%3/4
A or B or C
A= $item =~ /^[\$\@\%\*\&]?\w+$/B= $item =~ /^-/C= $item =~ s/^(<\w+)>$/$1/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | elsif ($item =~ /^:\w+$/) { $self->export_one_tag ($module,$version,$item, $items) } | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | print VERBOSE "(Exporter::VA) It's not syntactically correct, so invoking .&unknown_feature callback. It's out of my hands.\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $self->callback ('.&unknown_feature', $module, $version, $item, $items); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | my %thing= reverse (SCALAR=>'$', ARRAY=>'@', HASH=>'%',CODE=>'&',IO=>'<',GLOB=>'*'); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _resolve_by_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_by_name: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 12 | my ($item, $home, $name)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 12 | ▶ | $name= $item if $name eq ''; # blank string means "same". | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 12 | ▶ | my $sigil= ($name =~ s/^([\$\@\%\&\<\*])//) ? $1 : '&'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 12 | my $thing= $thing{$sigil}; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 12 | ▶ | Err "(Exporter::VA) Improper export definition for item $item: invalid symbol name syntax: $name" unless defined $thing; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 12 | my $globref= ${"$home\::"}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | 12 | ▶ | Err "(Exporter::VA) Symbol to export does not exist: *$home\::$name" unless defined $globref; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 12 | return *{$globref}{$thing}; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } # _resolve_by_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } # private vars scope | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub _resolve_by_versionlist | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_by_versionlist: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | my ($self, $module, $desired_version, $item, $param_tail)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | my $versionlist= $$self{$item}; # I still have the $item name for callbacks and error messages | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | my ($got_version, $result)= _match_vstring_list ($versionlist, $desired_version); | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | print VERBOSE "(Exporter::VA) wanted $item version ", _format_vstring($desired_version), ", choose ", _format_vstring($got_version), "\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | if $$self{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | return resolve (@_[0..4], $result); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sub _resolve_by_hardlink | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_by_hardlink: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | my ($item, $hardlink)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | # This function just provides error checking. Returning wrong kind of ref can cause problems! | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | ▶ | Err "(Exporter::VA) Improper export definition for item $item: ref to scalar must contain \\\\&code" unless ref($hardlink) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 14 | return $hardlink; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | sub resolve | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 45 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 45 | my ($self, $module, $version, $item, $param_tail, $value)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 45 | ▶ | $value= $$self{$item} unless defined ($value); # normally lookup, can supply ahead of time for recursive call. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 45 | ▶ | if (!defined $value && $item =~ /^&(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value and $item =~ /^&(.+)$/
MC/DC50%1/2
not defined $value and $item =~ /^&(.+)$/
not defined $value
$item =~ /^&(.+)$/
Truth table66%2/3
not(A) and B
A= not defined $valueB= $item =~ /^&(.+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # it might be entered in the export def without the sigil. | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 8 | my $base= $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | 8 | $value= delete $$self{$base}; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 8 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | $$self{$item}= $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | print VERBOSE "(Exporter::VA) adding leading & to ($base) entry in export definition\n" if $$self{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 45 | ▶ | return $self->callback ('.&unknown_import', $module, $version, $item, $param_tail) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | unless defined $value; # not listed in export def. | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 45 | my $type= ref $value; # what is it? Lots of different ways to list it. | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 45 | ▶ | return _resolve_by_name ($item, $$self{'..home'}, $value) unless $type; # scalar is a name in the home package. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 33 | ▶ | return &_resolve_by_versionlist if $type eq 'ARRAY-seen'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 28 | ▶ | if ($type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | _normalize_vstring_list ($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return &_resolve_by_versionlist; | |||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 27 | ▶ | return $value->(@_) if $type eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 14 | return _resolve_by_hardlink ($item, $$value); | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | Err "(Exporter::VA) Invalid export definition for item $item"; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | sub export_one_symbol # or pragma | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 35 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_one_symbol: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 35 | my ($self, $module, $version, $item, $param_tail)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 35 | ▶ | my $sigil= ($item =~ s /^([\$\@\%\*\&\-\<])//) ? $1 : '&'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 35 | ▶ | Warn qq((Exporter::VA) warning: importing symbol "$sigil$item" which begins with an underscore) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | if substr($item,0,1) eq '_'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 35 | my $X= $self->resolve ($module, $version, "$sigil$item", $param_tail); | |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 35 | ▶ | if (defined $X && $sigil ne '-') { # skip the import if it's callback-only | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $X and $sigil ne "-"
MC/DC50%1/2
defined $X and $sigil ne "-"
defined $X
$sigil ne "-"
Truth table66%2/3
A and B
A= defined $XB= $sigil ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 31 | my $worklist= $self->worklist(); | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 31 | my $name= "${module}::$item"; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 31 | $$worklist{$name}= $X; # duplicates take last resolution with no errors. | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 31 | ▶ | print VERBOSE qq(Got It: *{"${module}::$item"}= $X\n) if $$self{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | sub worklist | ||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 44 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
worklist: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 44 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 44 | return $$self{'..worklist'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | sub _process_worklist | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_worklist: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 13 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 13 | my $worklist= $self->worklist(); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 13 | ▶ | while (my ($left, $right)= each (%$worklist)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 30 | eval { *{$left}= $right; }; # this better be the right kind of thing! | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | 30 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | Err "(Exporter::VA) Could not process import for item '$left' = $right."; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | sub export_one_tag | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_one_tag: called CC=9 SCAR=22.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | my ($self, $module, $desired_version, $item, $param_tail)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 5 | ▶ | Warn qq((Exporter::VA) warning: importing tag "$item" which begins with an underscore) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | if substr($item,1,1) eq '_'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # my $home= $$self{'..home'}; # package I'm exporting =from= | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | RESTART: | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | my $list= $$self{$item}; | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | 6 | ▶ | Err "(Exporter::VA) no such export tag '$item'" unless defined $list; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 6 | my $type= ref $list; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 6 | ▶ | if ($type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # identify it, and change $type. | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 6 | ▶ | return if @$list == 0; # empty list is OK. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | ▶ | if (is_vstring($$list[0])) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | _normalize_vstring_list ($list); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | $type= 'ARRAY-seen'; | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5 | $type= 'ARRAY-tags'; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5 | bless $list, $type; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 6 | ▶ | if ($type eq 'ARRAY-seen') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | my ($got_version, $result)= _match_vstring_list ($list, $desired_version); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | print VERBOSE "(Exporter::VA) wanted $item version ", _format_vstring($desired_version), ", choose ", _format_vstring($got_version), "\n" | ||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | if $$self{'.verbose_import'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | $item= $result; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | goto RESTART; | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | elsif ($type eq 'ARRAY-tags') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | my @copy= @$list; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | 5 | $self->export ($module, $desired_version, \@copy); | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ## would add support for other types here, e.g. callbacks. | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | else { Err "(Exporter::VA) export tag '$item' is not a list ref" } | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | sub callback | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
callback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 26 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 26 | my $cb_name= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 26 | my $func= $$self{$cb_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | # they should be fully populated, putting in default behavior if it doesn't exist. | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # this is not "try to callback..." so if not found it is an error. | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 26 | $func-> ($self, @_); | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | my %defaults= ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | '.&unknown_type' => sub { Err "(Exporter::VA) import parameter is not a string" }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | '.&unknown_feature' => sub { Err "(Exporter::VA) import parameter \"$_[3]\" is not syntactically correct" }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | '.&unknown_import' => sub { Err "(Exporter::VA) import parameter \"$_[3]\" is not listed as an export" }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | '.check_user_option' => sub { return "unknown option"}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | '.warnings' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 6 | ▶ | '.&begin' => sub {}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 10 | ▶ | '.&end' => sub {}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | '--verbose_import' => sub { ++$_[0]->{'.verbose_import'} }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | '--dump' => sub { $_[0]->dump() } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | sub _populate_defaults | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 13 | ▶ | { # helper for setup. | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_populate_defaults: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # populate callbacks and settings that were not specified | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 13 | ▶ | while (my ($key,$value)= each %defaults) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 117 | ▶ | $$self{$key}= $value unless exists $$self{$key}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 13 | ▶ | $$self{'.default_VERSION'}= normalize_vstring (${"$self->{'..home'}::VERSION"}) unless exists $$self{'.default_VERSION'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } # end scope for populate_defaults | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | sub _expand_plain | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expand_plain: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 13 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 13 | my $plainspec= delete $$self{'.plain'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | 13 | ▶ | return unless defined $plainspec; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 2 | ▶ | while (my $value = shift @$plainspec) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 11 | ▶ | $value =~ /^([\$\@\&\%:<])?(\w+)>?$/ or Err "(Exporter::VA) item '$value' in .plain list is not a legal symbol or tag name"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 11 | my ($sigil, $body)= ($1,$2); | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | 11 | ▶ | $sigil= '&' unless defined $sigil; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 11 | ▶ | if ($sigil eq ":") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # this one is different | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 2 | push @$plainspec, @{$$self{$value}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | # could do more error checking: make sure tag exists, and doesn't contain v-string list. | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 11 | $value= "$sigil$body"; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | 11 | ▶ | next if exists $$self{$value}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 8 | ▶ | next if $sigil eq '&' && exists $$self{$body}; # present without the leading & for a function | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$sigil eq "&" and exists $self->{$body}
MC/DC100%2/2
$sigil eq "&" and exists $self->{$body}
$sigil eq "&"
exists $self->{$body}
Truth table100%3/3
A and B
A= $sigil eq "&"B= exists $self->{$body}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | ▶ | next if $sigil eq '<' && exists $$self{"$body>"}; # present with trailing > for a handle | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sigil eq "<" and exists $$self{"$body>"}
MC/DC0%0/2
$sigil eq "<" and exists $$self{"$body>"}
$sigil eq "<"
exists $$self{"$body>"}
Truth table33%1/3
A and B
A= $sigil eq "<"B= exists $$self{"$body>"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # not already present, so add it. | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | $$self{$value}=$value; | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | sub _get_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_VERSION: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 15 | my $home= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 15 | my $v= ${"${home}::VERSION"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | 15 | ▶ | Err "(Exporter::VA) module $home does not contain a package global \$VERSION" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | unless defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 15 | return normalize_vstring ($v); | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||
| 411 | { # extra scope for variable local to function | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | my %check_code= ( | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | # could point to more detailed checking function, or just 1 for OK/allowed with no additional testing. | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | '.allowed_VERSIONS' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 416 | '.&begin' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 417 | '.check_user_option' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | '.default_VERSION' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | '.&end' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | '.plain' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | '.&unknown_feature' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | '.&unknown_import' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | '.&unknown_type' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | '.verbose_import' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | '.warnings' => 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | sub _check_warning_option($$$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 161 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_warning_option: called CC=5 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 161 | my ($self, $item, $value)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 431 | 161 | ▶ | if ($item =~ /^\.&?\p{IsUpper}/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # a user-defined option. | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $self->check_user_option ($item); | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 161 | ▶ | return if $item =~ /^\.\./; # internal state information | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # check for known options. | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 111 | my $checker= $check_code{$item}; | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if (!defined $checker) { Warn qq{(Exporter::VA) unknown option present: "$item"} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | elsif (ref $checker) { $checker->($item,$value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | # else it exists but doesn't have special checking code, so no messages. | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } # scope for _check_warning_option | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | sub _check_warning_tag($$) | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 30 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_warning_tag: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 30 | my ($item, $value)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | sub _check_warning_pragma($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 29 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_warning_pragma: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 29 | my ($item, $value)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | sub _check_warning_identifier($$) | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 67 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_warning_identifier: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 67 | my ($item, $value)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | sub _check_for_warnings | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_for_warnings: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 13 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 13 | ▶ | while (my($key, $value)= each %$self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 287 | my $firstchar= substr($key,0,1); | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 287 | ▶ | if ($firstchar eq '.') { _check_warning_option ($self, $key, $value) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 30 | elsif ($firstchar eq ':') {_check_warning_tag ($key, $value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 467 | 29 | elsif ($firstchar eq '-') {_check_warning_pragma ($key, $value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 67 | else {_check_warning_identifier ($key, $value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | sub setup | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 13 | my ($self, $home)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 13 | my $existing_home= $$self{'..home'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | 13 | ▶ | if (defined $existing_home && $existing_home ne $home) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $existing_home and $existing_home ne $home
MC/DC0%0/2
defined $existing_home and $existing_home ne $home
defined $existing_home
$existing_home ne $home
Truth table66%2/3
A and B
A= defined $existing_homeB= $existing_home ne $home
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | Err "(Exporter::VA) reuse of \%EXPORT in module $home is not allowed."; | |||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 13 | $$self{'..home'}= $home; | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 13 | $$self{'..worklist'}= {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | 13 | $$self{'..max_VERSION'}= _get_VERSION ($home); | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 13 | $self->_expand_plain(); | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | 13 | $self->_populate_defaults(); | |||||||||||||||||||||||||||||||||||||||||||||
| 484 | 13 | ▶ | if (exists $$self{'.allowed_VERSIONS'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | $_= normalize_vstring($_) foreach (@{$$self{'.allowed_VERSIONS'}}); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 13 | ▶ | $self->_check_for_warnings() if $$self{'.warnings'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | my $client_export_def; | |||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | sub begin | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
begin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | my ($blessed_export_def, $caller, $version, $symbol, $param_list_tail)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | $client_export_def= find_export_def ($caller, $param_list_tail); | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | sub find_export_def | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_export_def: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | my ($caller, $params)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | # first, try to locate hash ref in parameter list. | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | foreach my $index (0..scalar(@$params)-1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 9 | my $val= $$params[$index]; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 9 | ▶ | if (ref ($val) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | splice @$params, $index, 1; # remove it | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | ▶ | splice @$params, $index-1, 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$index > 0 and $$params[$index - 1] eq "-def"
MC/DC50%1/2
$index > 0 and $$params[$index - 1] eq "-def"
$index > 0
$$params[$index - 1] eq "-def"
Truth table66%2/3
A and B
A= $index > 0B= $$params[$index - 1] eq "-def"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | if $index>0 && $$params[$index-1] eq '-def'; # remove optional explicit switch | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 2 | return $val; # return it | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # look for package variable in caller. | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | return \%{"$caller\::EXPORT"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | sub export_import | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # called to export a custom import function to *my* client, when Export::VA is used. | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_import: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 3 | my ($VA_export_def, $caller, $version, $symbol, $param_list_tail)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | 3 | $client_export_def= bless $client_export_def, "Exporter::VA"; | |||||||||||||||||||||||||||||||||||||||||||||
| 522 | 3 | return generate_import ($client_export_def); | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | sub export_VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # called to export a custom VERSION function to *my* client, when Export::VA is used. | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_VERSION: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # my ($VA_export_def, $caller, $version, $symbol, $param_list_tail)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # the above line documents the parameters, but I don't need any of them so it's commented out. | ||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 3 | return generate_VERSION ($client_export_def); | |||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | sub export_AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # called to export a custom AUTOLOAD function to *my* client, when Export::VA is used. | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export_AUTOLOAD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # my ($VA_export_def, $caller, $version, $symbol, $param_list_tail)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # the above line documents the parameters, but I don't need any of them so it's commented out. | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | return _generate_AUTOLOAD ($client_export_def); | |||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } # end scope around $client_export_def | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | sub autoload_symbol | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autoload_symbol: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 3 | my ($self, $symbol, @extra)= @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | 3 | my %memory; | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | 3 | my $home= $self->{'..home'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 551 | 4 | ▶ | my $thunk= sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 4 | my $retval= eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | 4 | my $caller= _calling_client(); # so I don't have to figure it out multiple times | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | 4 | my $f= $memory{$caller}; | |||||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | ▶ | unless (defined $f) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 4 | $f= $memory{$caller}= $self->resolve ($caller, $home->VERSION(undef,$caller), '&'.$symbol, [@extra]); | |||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 4 | goto &$f; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 4 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 4 | carp "(Exporter::VA) Cannot redirect to versioned function ($@)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 4 | return $retval; | |||||||||||||||||||||||||||||||||||||||||||||
| 564 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 3 | *{"${home}::$symbol"}= $thunk; | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | sub _generate_AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_AUTOLOAD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | my $client_export_def= shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | ▶ | return sub { # the generated AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | my $AUTOLOAD= $Exporter::VA::AUTOLOAD; # save the global in case of recursion. | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | 3 | my $func= $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | 3 | $func =~ s/.*:://; # not checking the actual module name. Might be inherited or re-routed or something. I shouldn't care, right? | |||||||||||||||||||||||||||||||||||||||||||||
| 576 | Err "(Exporter::VA) Generated $client_export_def->{'..home'}::AUTOLOAD can't find export definition for $func." | ||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 3 | ▶ | unless exists $client_export_def->{$func} || exists $client_export_def->{'&' . $func}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $client_export_def->{$func} or exists $$client_export_def{'&' . $func}
MC/DC50%1/2
exists $client_export_def->{$func} or exists $$client_export_def{'&' . $func}
exists $client_export_def->{$func}
exists $$client_export_def{'&' . $func}
Truth table66%2/3
A or B
A= exists $client_export_def->{$func}B= exists $$client_export_def{'&' . $func}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | $client_export_def->autoload_symbol ($func); | |||||||||||||||||||||||||||||||||||||||||||||
| 579 | 2 | goto &$AUTOLOAD; # try it again. | |||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||
| 583 | ## main code. | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | my $export_def= bless (\%EXPORT, __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | ▶ | use vars qw/*import *VERSION/; # silence a warning when syntax checking the .pm by itself | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | *import= generate_import ($export_def); | |||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | *VERSION= generate_VERSION ($export_def); | |||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 594 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||