« lib/Perl/ToPerl6/TransformerParameter/Behavior/StringList.pm
↑ Summary
lib/Perl/ToPerl6/Transformer/Variables/ReplaceNegativeIndex.pm »
| 1 | package Perl::ToPerl6::TransformerFactory; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use File::Spec::Unix qw(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use List::MoreUtils qw(any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use Perl::ToPerl6::Utils qw{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | :characters | ||||||||||||||||||||||||||||||||||||||||||
| 15 | $TRANSFORMER_NAMESPACE | ||||||||||||||||||||||||||||||||||||||||||
| 16 | :data_conversion | ||||||||||||||||||||||||||||||||||||||||||
| 17 | transformer_long_name | ||||||||||||||||||||||||||||||||||||||||||
| 18 | transformer_short_name | ||||||||||||||||||||||||||||||||||||||||||
| 19 | :internal_lookup | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | }; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 17 | ▶ | use Perl::ToPerl6::TransformerConfig; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | ▶ | use Perl::ToPerl6::Exception::AggregateConfiguration; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 17 | ▶ | use Perl::ToPerl6::Exception::Configuration; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 17 | ▶ | use Perl::ToPerl6::Exception::Fatal::Generic qw{ throw_generic }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 17 | ▶ | use Perl::ToPerl6::Exception::Fatal::Internal qw{ throw_internal }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | use Perl::ToPerl6::Exception::Fatal::TransformerDefinition | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 17 | ▶ | qw{ throw_transformer_definition }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 17 | ▶ | use Perl::ToPerl6::Exception::Configuration::NonExistentTransformer qw< >; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 17 | ▶ | use Perl::ToPerl6::Utils::Constants qw{ :profile_strictness }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 17 | ▶ | use Exception::Class; # this must come after "use P::C::Exception::*" | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # Globals. Ick! | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 17 | my @site_transformer_names = (); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # Blech!!! This is ug-lee. Belongs in the constructor. And it shouldn't be | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # called "test" mode. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 52 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 52 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 52 | my $test_mode = $args{-test}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 52 | my $extra_test_transformers = $args{'-extra-test-transformers'}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 52 | ▶ | if ( not @site_transformer_names ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 17 | my $eval_worked = eval { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 17 | require Module::Pluggable; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | Module::Pluggable->import(search_path => $TRANSFORMER_NAMESPACE, | |||||||||||||||||||||||||||||||||||||||||
| 52 | require => 1, inner => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | @site_transformer_names = plugins(); #Exported by Module::Pluggable | |||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 17 | ▶ | if (not $eval_worked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $EVAL_ERROR ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | throw_generic | |||||||||||||||||||||||||||||||||||||||||
| 60 | qq<Can't load Transformers from namespace "$TRANSFORMER_NAMESPACE": $EVAL_ERROR>; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | throw_generic | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | qq<Can't load Transformers from namespace "$TRANSFORMER_NAMESPACE" for an unknown reason.>; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 17 | ▶ | if ( not @site_transformer_names ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | throw_generic | |||||||||||||||||||||||||||||||||||||||||
| 69 | qq<No Transformers found in namespace "$TRANSFORMER_NAMESPACE".>; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # In test mode, only load native transformers, not third-party ones. So this | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # filters out any transformer that was loaded from within a directory called | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # "blib". During the usual "./Build test" process this works fine, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # but it doesn't work if you are using prove to test against the code | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # directly in the lib/ directory. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 52 | ▶ | if ( $test_mode && any {m/\b blib \b/xms} @INC ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$test_mode and &any(sub {
/\b blib \b/msx;
}
, @INC)
MC/DC50%1/2
$test_mode and &any(sub {
/\b blib \b/msx;
}
, @INC)
$test_mode
&any(sub {
/\b blib \b/msx;
}
, @INC)
Truth table66%2/3
A and B
A= $test_modeB= &any(sub {
/\b blib \b/msx;
}
, @INC)
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 22 | @site_transformer_names = _modules_from_blib( @site_transformer_names ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 22 | ▶ | if ($extra_test_transformers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | my @extra_transformer_full_names = | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | map { "${TRANSFORMER_NAMESPACE}::$_" } @{$extra_test_transformers}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | push @site_transformer_names, @extra_transformer_full_names; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 52 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # Shuffle transformer order based on preferences, if any. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # Transformers can request to run before or after a given list of other | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # transformers. This code rewrites the list as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # If transformer A requests to be run *before* transformer B, then we instead | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # state that transformer B must be run *after* transformer A. It's the logical | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # dual, but having only one kind of dependency to deal with makes it easier. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 32 | ▶ | sub _invert_dependencies { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_invert_dependencies: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 32 | my ($dependencies) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 32 | for my $name ( keys %{ $dependencies } ) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1180 | ▶ | next unless $dependencies->{$name}{before}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 124 | for my $_name ( keys %{ $dependencies->{$name}{before} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 109 | 186 | $dependencies->{$_name}{after}{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # Collect the preferences for all the transformers we want to run. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 32 | ▶ | sub _collect_preferences { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_collect_preferences: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 32 | my (@transformers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 32 | my $preferences; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 32 | for my $transformer ( @transformers ) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 1180 | my $ref_name = ref($transformer); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 1180 | $ref_name =~ s< ^ Perl\::ToPerl6\::Transformer\:: ><>x; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 1180 | $preferences->{$ref_name} = { }; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # Get the list of transformers this module wants to run *after*. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 1180 | ▶ | if ( $transformer->can('run_before') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 124 | my @before = $transformer->run_before(); | |||||||||||||||||||||||||||||||||||||||||
| 129 | $preferences->{$ref_name}{before} = { map { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 124 | s< ^ Perl\::ToPerl6\::Transformer\:: ><>x; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 186 | $_ => 1 | |||||||||||||||||||||||||||||||||||||||||
| 132 | } @before }; | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # Get the list of transformers this module wants to run *before*. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1180 | ▶ | if ( $transformer->can('run_after') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 218 | my @after = $transformer->run_after(); | |||||||||||||||||||||||||||||||||||||||||
| 139 | $preferences->{$ref_name}{after} = { map { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 218 | s< ^ Perl\::ToPerl6\::Transformer\:: ><>x; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 218 | $_ => 1 | |||||||||||||||||||||||||||||||||||||||||
| 142 | } @after }; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 32 | return $preferences; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 32 | ▶ | sub _validate_preferences { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_preferences: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 32 | my ($preferences) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 32 | for my $k ( keys %{ $preferences } ) { | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1180 | ▶ | if ( $preferences->{$k} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$preferences->{$k} and $preferences->{$k}{"after"}
MC/DC50%1/2
$preferences->{$k} and $preferences->{$k}{"after"}
$preferences->{$k}
$preferences->{$k}{"after"}
Truth table66%2/3
A and B
A= $preferences->{$k}B= $preferences->{$k}{"after"}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | $preferences->{$k}{after} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 218 | for my $_k ( keys %{ $preferences->{$k}{after} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 156 | 218 | ▶ | next if exists $preferences->{$_k}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | die "Module $k wanted to run after module $_k, which was not found!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 1180 | ▶ | if ( $preferences->{$k} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$preferences->{$k} and $preferences->{$k}{"before"}
MC/DC50%1/2
$preferences->{$k} and $preferences->{$k}{"before"}
$preferences->{$k}
$preferences->{$k}{"before"}
Truth table66%2/3
A and B
A= $preferences->{$k}B= $preferences->{$k}{"before"}
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | $preferences->{$k}{before} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 124 | for my $_k ( keys %{ $preferences->{$k}{before} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 186 | ▶ | next if exists $preferences->{$_k}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | die "Module $k wanted to run before module $_k, which was not found!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # Transformers can now request to be run before or after a given transformer. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | # Or transformers. | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # We honor those requests here, by collecting the transformers, calling | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # ->run_before() and/or ->run_after(), to get what transformers they must | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # run after or before. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # Then we restate the 'before' requests in terms of 'after', dying for the | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # moment if we can't find a module that a given module wants to run 'after'. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # After restating 'before' as 'after', we sort the modules in order of | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # preference, then return the list in preference order. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 32 | ▶ | sub topological_sort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
topological_sort: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 32 | my @transformers = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 32 | my @ordered; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | my %object; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 32 | for my $transformer ( @transformers ) { | |||||||||||||||||||||||||||||||||||||||||
| 189 | 1180 | my $ref_name = ref $transformer; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 1180 | $ref_name =~ s< ^ Perl\::ToPerl6\::Transformer\:: ><>x; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 1180 | $object{$ref_name} = $transformer; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 32 | my $preferences = _collect_preferences(@transformers); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 32 | _validate_preferences($preferences); | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 32 | _invert_dependencies($preferences); | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | # This algorithm can potentially loop if it encounters a cycle in the | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # dependencies. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # Specifically, the hash could look like this at the end: | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # %foo = ( A => { after => { B => 1 } }, B => { after => { A => 1 } } ); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # In which case this algorithm wouldn't terminate. | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # So we count down from the number of keys in the original hash. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # This should give us plenty of time to detect cycles. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # The cycle could be arbitrarily long, and while there are fancy | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # algorithms to detect those, I'm not going to bother. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # Keeping the module names in a stable order reduces the likelihood | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # that a cycle will "trap" (I.E. come before) a module that's not | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # involved in the cycle. It still could happen, but I'll worry about that | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # later on. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | # | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 32 | my %final; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 32 | my $iterations = keys %{ $preferences }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 32 | ▶ | while( keys %{ $preferences } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 64 | ▶ | last if $iterations-- <= 0; # DO NOT REMOVE THIS. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 64 | for my $name ( sort keys %{ $preferences } ) { | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # If a module needs to run after one or more modules, try to | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # satisfy its request. | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 1367 | ▶ | if ( $preferences->{$name}{after} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # Walk the list of modules it needs to run after. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 529 | my $max = 0; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 529 | for my $_name ( keys %{ $preferences->{$name}{after} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # If it needs to run after a module we haven't placed in | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # order, then abandon the loop. | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 591 | ▶ | if ( !exists $final{$_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 187 | $max = -1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 187 | last; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 404 | $max = max($final{$_name},$max); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # If we haven't abandoned the loop, then | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # add the module *after* the last module in order | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # and delete the module from the preferences list. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 529 | ▶ | if ( $max >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 342 | $final{$name} = $max + 1; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 342 | delete $preferences->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # The module doesn't need to be run after any given module. | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # So put it directly on the list, in group 0. | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # | ||||||||||||||||||||||||||||||||||||||||||
| 257 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 838 | $final{$name} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 838 | delete $preferences->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # If there are any keys remaining in the preferences array, it's possible | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # that the algorithm didn't sort dependencies correctly, but it is | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # vastly more likely to be the case that we've encountered a cycle. | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # Die, telling the user what happened. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | # | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 32 | ▶ | if ( keys %{ $preferences } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | die "Found a preference loop among: " . join("\n", keys %{ $preferences }); | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 32 | my %inverse; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 32 | push @{$inverse{$final{$_}}}, $_ for keys %final; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 32 | for ( sort keys %inverse ) { | |||||||||||||||||||||||||||||||||||||||||
| 276 | 95 | push @ordered, map { $object{$_} } @{$inverse{$_}}; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 32 | return @ordered; | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # Some static helper subs | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 22 | ▶ | sub _modules_from_blib { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_modules_from_blib: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 22 | my (@modules) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 22 | return grep { _was_loaded_from_blib( _module2path($_) ) } @modules; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 836 | ▶ | sub _module2path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_module2path: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 836 | ▶ | my $module = shift || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 836 | return File::Spec::Unix->catdir(split m/::/xms, $module) . '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 836 | ▶ | sub _was_loaded_from_blib { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_was_loaded_from_blib: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 836 | ▶ | my $path = shift || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 836 | my $full_path = $INC{$path}; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 836 | ▶ | return $full_path && $full_path =~ m/ (?: \A | \b b ) lib \b /xms; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$full_path && $full_path =~ / (?: \A | \b b ) lib \b /msx
MC/DC0%0/2
$full_path && $full_path =~ / (?: \A | \b b ) lib \b /msx
$full_path
$full_path =~ / (?: \A | \b b ) lib \b /msx
Truth table33%1/3
A && B
A= $full_pathB= $full_path =~ / (?: \A | \b b ) lib \b /msx
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 119 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 119 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 119 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 119 | $self->_init( %args ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 119 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 119 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 119 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 119 | my $profile = $args{-profile}; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 119 | ▶ | $self->{_profile} = $profile | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | or throw_internal q{The -profile argument is required}; | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 119 | my $incoming_errors = $args{-errors}; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 119 | my $profile_strictness = $args{'-profile-strictness'}; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 119 | ▶ | $profile_strictness ||= $PROFILE_STRICTNESS_DEFAULT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$profile_strictness ||= $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_DEFAULT
MC/DC0%0/2
$profile_strictness ||= $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_DEFAULT
$profile_strictness
$Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_DEFAULT
Truth table66%2/3
A ||= B
A= $profile_strictnessB= $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_DEFAULT
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 119 | $self->{_profile_strictness} = $profile_strictness; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 119 | ▶ | if ( $profile_strictness ne $PROFILE_STRICTNESS_QUIET ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 119 | my $errors; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | # If we're supposed to be strict or problems have already been found... | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 119 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$profile_strictness eq $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_FATAL or $incoming_errors and @{$incoming_errors->exceptions;}
$incoming_errors and @{$incoming_errors->exceptions;}
MC/DC100%3/3
$profile_strictness eq $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_FATAL or $incoming_errors and @{$incoming_errors->exceptions;}
$profile_strictness eq $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_FATAL
$incoming_errors
@{$incoming_errors->exceptions;}
Truth table100%4/4
A or B and C
A= $profile_strictness eq $Perl::ToPerl6::TransformerFactory::PROFILE_STRICTNESS_FATALB= $incoming_errorsC= @{$incoming_errors->exceptions;}
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | $profile_strictness eq $PROFILE_STRICTNESS_FATAL | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 70 | or ( $incoming_errors and @{ $incoming_errors->exceptions() } ) | |||||||||||||||||||||||||||||||||||||||||
| 333 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 40 | ▶ | $errors = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | $incoming_errors | ||||||||||||||||||||||||||||||||||||||||||
| 336 | ? $incoming_errors | ||||||||||||||||||||||||||||||||||||||||||
| 337 | : Perl::ToPerl6::Exception::AggregateConfiguration->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 119 | $self->_validate_transformers_in_profile( $errors ); | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 119 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $incoming_errors and $errors and $errors->has_exceptions
not $incoming_errors and $errors
MC/DC0%0/3
not $incoming_errors and $errors and $errors->has_exceptions
not $incoming_errors
$errors
$errors->has_exceptions
Truth table75%3/4
not(A) and B and C
A= not $incoming_errorsB= $errorsC= $errors->has_exceptions
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | not $incoming_errors | ||||||||||||||||||||||||||||||||||||||||||
| 344 | and $errors | ||||||||||||||||||||||||||||||||||||||||||
| 345 | and $errors->has_exceptions() | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $errors->rethrow(); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 119 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 1337 | ▶ | sub create_transformer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_transformer: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1337 | my ($self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | my $transformer_name = $args{-name} | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 1337 | ▶ | or throw_internal q{The -name argument is required}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | # Normalize transformer name to a fully-qualified package name | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 1336 | $transformer_name = transformer_long_name( $transformer_name ); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 1336 | my $transformer_short_name = transformer_short_name( $transformer_name ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # Get the transformer parameters from the user profile if they were | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # not given to us directly. If none exist, use an empty hash. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 1336 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||||||||||||||||
| 371 | 1336 | my $transformer_config; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 1336 | ▶ | if ( $args{-params} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | $transformer_config = | ||||||||||||||||||||||||||||||||||||||||||
| 374 | Perl::ToPerl6::TransformerConfig->new( | ||||||||||||||||||||||||||||||||||||||||||
| 375 | $transformer_short_name, $args{-params} | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 42 | ); | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 1294 | $transformer_config = $profile->transformer_params($transformer_name); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 1294 | ▶ | $transformer_config ||= | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$transformer_config ||= "Perl::ToPerl6::TransformerConfig"->new($transformer_short_name)
MC/DC0%0/2
$transformer_config ||= "Perl::ToPerl6::TransformerConfig"->new($transformer_short_name)
$transformer_config
"Perl::ToPerl6::TransformerConfig"->new($transformer_short_name)
Truth table33%1/3
A ||= B
A= $transformer_configB= "Perl::ToPerl6::TransformerConfig"->new($transformer_short_name)
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | Perl::ToPerl6::TransformerConfig->new( $transformer_short_name ); | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | # Pull out base parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 1336 | return $self->_instantiate_transformer( $transformer_name, $transformer_config ); | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 31 | ▶ | sub create_all_transformers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_all_transformers: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 31 | my ( $self, $incoming_errors ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 31 | ▶ | my $errors = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | $incoming_errors | ||||||||||||||||||||||||||||||||||||||||||
| 396 | ? $incoming_errors | ||||||||||||||||||||||||||||||||||||||||||
| 397 | : Perl::ToPerl6::Exception::AggregateConfiguration->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 31 | my @transformers; | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 31 | foreach my $name ( site_transformer_names() ) { | |||||||||||||||||||||||||||||||||||||||||
| 401 | 1178 | my $transformer = eval { $self->create_transformer( -name => $name ) }; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 1178 | $errors->add_exception_or_rethrow( $EVAL_ERROR ); | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 1178 | ▶ | if ( $transformer ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 1178 | push @transformers, $transformer; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 31 | ▶ | if ( not $incoming_errors and $errors->has_exceptions() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $incoming_errors and $errors->has_exceptions
MC/DC0%0/2
not $incoming_errors and $errors->has_exceptions
not $incoming_errors
$errors->has_exceptions
Truth table66%2/3
not(A) and B
A= not $incoming_errorsB= $errors->has_exceptions
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $errors->rethrow(); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 31 | my @sorted = topological_sort(@transformers); | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 31 | return @sorted; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 164 | ▶ | sub site_transformer_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
site_transformer_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 164 | my @sorted_transformer_names = sort @site_transformer_names; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 164 | return @sorted_transformer_names; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 1455 | ▶ | sub _profile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_profile: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 1455 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 1455 | return $self->{_profile}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | # This two-phase initialization is caused by the historical lack of a | ||||||||||||||||||||||||||||||||||||||||||
| 437 | # requirement for Transformers to invoke their super-constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 1336 | ▶ | sub _instantiate_transformer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_instantiate_transformer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 1336 | my ($self, $transformer_name, $transformer_config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 1336 | $transformer_config->set_profile_strictness( $self->{_profile_strictness} ); | |||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 1336 | my $transformer = eval { $transformer_name->new( %{$transformer_config} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 1336 | _handle_transformer_instantiation_exception( | |||||||||||||||||||||||||||||||||||||||||
| 445 | $transformer_name, | ||||||||||||||||||||||||||||||||||||||||||
| 446 | $transformer, # Note: being used as a boolean here. | ||||||||||||||||||||||||||||||||||||||||||
| 447 | $EVAL_ERROR, | ||||||||||||||||||||||||||||||||||||||||||
| 448 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 1296 | $transformer->__set_config( $transformer_config ); | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 1296 | my $eval_worked = eval { $transformer->__set_base_parameters(); 1; }; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 1296 | _handle_transformer_instantiation_exception( | |||||||||||||||||||||||||||||||||||||||||
| 454 | $transformer_name, $eval_worked, $EVAL_ERROR, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 1295 | return $transformer; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 2632 | ▶ | sub _handle_transformer_instantiation_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_transformer_instantiation_exception: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 2632 | my ($transformer_name, $eval_worked, $eval_error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 2632 | ▶ | if (not $eval_worked) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 41 | ▶ | if ($eval_error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 41 | my $exception = Exception::Class->caught(); | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 41 | ▶ | if (ref $exception) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 39 | $exception->rethrow(); | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | throw_transformer_definition( | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | qq<Unable to create transformer "$transformer_name": $eval_error>); | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | throw_transformer_definition( | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | qq<Unable to create transformer "$transformer_name" for an unknown reason.>); | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 2591 | return; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 119 | ▶ | sub _validate_transformers_in_profile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_transformers_in_profile: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 119 | my ($self, $errors) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 119 | my $profile = $self->_profile(); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 119 | my %known_transformers = hashify( $self->site_transformer_names() ); | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 119 | for my $transformer_name ( $profile->listed_transformers() ) { | |||||||||||||||||||||||||||||||||||||||||
| 491 | 55 | ▶ | if ( not exists $known_transformers{$transformer_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | my $message = qq{Transformer "$transformer_name" is not installed.}; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | if ( $errors ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 2 | $errors->add_exception( | |||||||||||||||||||||||||||||||||||||||||
| 496 | Perl::ToPerl6::Exception::Configuration::NonExistentTransformer->new( | ||||||||||||||||||||||||||||||||||||||||||
| 497 | transformer => $transformer_name, | ||||||||||||||||||||||||||||||||||||||||||
| 498 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 499 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | warn qq{$message\n}; | |||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 119 | return; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | __END__ | ||||||||||||||||||||||||||||||||||||||||||