« lib/Perl/ToPerl6/Transformer/Packages/RewriteUsages.pm
↑ Summary
lib/Perl/ToPerl6/TransformerParameter/Behavior/Boolean.pm »
| 1 | package Perl::ToPerl6::ProfilePrototype; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use 5.006001; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use English qw(-no_match_vars); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | ▶ | use Perl::ToPerl6::Config qw{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 2 | ▶ | use Perl::ToPerl6::Transformer qw{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use Perl::ToPerl6::Utils qw{ :characters }; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use overload ( q{""} => 'to_string' ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||
| 15 | |||||||||||||
| 16 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 17 | 2 | my ($class, %args) = @_; | |||||||||||
| 18 | 2 | my $self = bless {}, $class; | |||||||||||
| 19 | |||||||||||||
| 20 | 2 | ▶ | my $transformers = $args{-transformers} || []; | ||||||||||
|
Condition100%2/2
$args{'-transformers'} || []
MC/DC100%1/1
$args{'-transformers'} || []
$args{'-transformers'}
Truth table100%2/2
A
A= $args{'-transformers'}
| |||||||||||||
| 21 | 2 | $self->{_transformers} = [ sort _by_type @{ $transformers } ]; | |||||||||||
| 22 | |||||||||||||
| 23 | 2 | my $comment_out_parameters = $args{'-comment-out-parameters'}; | |||||||||||
| 24 | 2 | ▶ | if (not defined $comment_out_parameters) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | 1 | $comment_out_parameters = 1; | |||||||||||
| 26 | } | ||||||||||||
| 27 | 2 | $self->{_comment_out_parameters} = $comment_out_parameters; | |||||||||||
| 28 | |||||||||||||
| 29 | 2 | my $configuration = $args{'-config'}; | |||||||||||
| 30 | 2 | ▶ | if (not $configuration) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 1 | $configuration = Perl::ToPerl6::Config->new(-profile => $EMPTY); | |||||||||||
| 32 | } | ||||||||||||
| 33 | 2 | $self->{_configuration} = $configuration; | |||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 2 | return $self; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | #----------------------------------------------------------------------------- | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | ▶ | sub _get_transformers { | ||||||||||
|
Subroutine
_get_transformers: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | 1 | my ($self) = @_; | |||||||||||
| 43 | |||||||||||||
| 44 | 1 | return $self->{_transformers}; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 2 | ▶ | sub _comment_out_parameters { | ||||||||||
|
Subroutine
_comment_out_parameters: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 2 | my ($self) = @_; | |||||||||||
| 49 | |||||||||||||
| 50 | 2 | return $self->{_comment_out_parameters}; | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | sub _configuration { | ||||||||||
|
Subroutine
_configuration: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | 1 | my ($self) = @_; | |||||||||||
| 55 | |||||||||||||
| 56 | 1 | return $self->{_configuration}; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | #----------------------------------------------------------------------------- | ||||||||||||
| 60 | |||||||||||||
| 61 | 2 | ▶ | sub _line_prefix { | ||||||||||
|
Subroutine
_line_prefix: called CC=2 SCAR=7.2
| |||||||||||||
| 62 | 2 | my ($self) = @_; | |||||||||||
| 63 | |||||||||||||
| 64 | 2 | ▶ | return $self->_comment_out_parameters() ? q{# } : $EMPTY; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | #----------------------------------------------------------------------------- | ||||||||||||
| 68 | |||||||||||||
| 69 | 1 | ▶ | sub to_string { | ||||||||||
|
Subroutine
to_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 70 | 1 | my ($self) = @_; | |||||||||||
| 71 | |||||||||||||
| 72 | 1 | my $prefix = $self->_line_prefix(); | |||||||||||
| 73 | 1 | my $configuration = $self->_configuration(); | |||||||||||
| 74 | |||||||||||||
| 75 | 1 | my $prototype = "# Globals\n"; | |||||||||||
| 76 | |||||||||||||
| 77 | 1 | $prototype .= $prefix; | |||||||||||
| 78 | 1 | $prototype .= q{necessity = }; | |||||||||||
| 79 | 1 | $prototype .= $configuration->necessity(); | |||||||||||
| 80 | 1 | $prototype .= "\n"; | |||||||||||
| 81 | |||||||||||||
| 82 | 1 | $prototype .= $prefix; | |||||||||||
| 83 | 1 | $prototype .= q{detail = }; | |||||||||||
| 84 | 1 | $prototype .= $configuration->detail(); | |||||||||||
| 85 | 1 | $prototype .= "\n"; | |||||||||||
| 86 | |||||||||||||
| 87 | 1 | $prototype .= $prefix; | |||||||||||
| 88 | 1 | $prototype .= q{force = }; | |||||||||||
| 89 | 1 | $prototype .= $configuration->force(); | |||||||||||
| 90 | 1 | $prototype .= "\n"; | |||||||||||
| 91 | |||||||||||||
| 92 | 1 | $prototype .= $prefix; | |||||||||||
| 93 | 1 | $prototype .= q{in-place = }; | |||||||||||
| 94 | 1 | $prototype .= $configuration->in_place(); | |||||||||||
| 95 | 1 | $prototype .= "\n"; | |||||||||||
| 96 | |||||||||||||
| 97 | 1 | $prototype .= $prefix; | |||||||||||
| 98 | 1 | $prototype .= q{only = }; | |||||||||||
| 99 | 1 | $prototype .= $configuration->only(); | |||||||||||
| 100 | 1 | $prototype .= "\n"; | |||||||||||
| 101 | |||||||||||||
| 102 | 1 | $prototype .= $prefix; | |||||||||||
| 103 | 1 | $prototype .= q{profile-strictness = }; | |||||||||||
| 104 | 1 | $prototype .= $configuration->profile_strictness(); | |||||||||||
| 105 | 1 | $prototype .= "\n"; | |||||||||||
| 106 | |||||||||||||
| 107 | 1 | $prototype .= $prefix; | |||||||||||
| 108 | 1 | $prototype .= q{color = }; | |||||||||||
| 109 | 1 | $prototype .= $configuration->color(); | |||||||||||
| 110 | 1 | $prototype .= "\n"; | |||||||||||
| 111 | |||||||||||||
| 112 | 1 | $prototype .= $prefix; | |||||||||||
| 113 | 1 | $prototype .= q{pager = }; | |||||||||||
| 114 | 1 | $prototype .= $configuration->pager(); | |||||||||||
| 115 | 1 | $prototype .= "\n"; | |||||||||||
| 116 | |||||||||||||
| 117 | 1 | $prototype .= $prefix; | |||||||||||
| 118 | 1 | $prototype .= q{top = }; | |||||||||||
| 119 | 1 | $prototype .= $configuration->top(); | |||||||||||
| 120 | 1 | $prototype .= "\n"; | |||||||||||
| 121 | |||||||||||||
| 122 | 1 | $prototype .= $prefix; | |||||||||||
| 123 | 1 | $prototype .= q{verbose = }; | |||||||||||
| 124 | 1 | $prototype .= $configuration->verbose(); | |||||||||||
| 125 | 1 | $prototype .= "\n"; | |||||||||||
| 126 | |||||||||||||
| 127 | 1 | $prototype .= $prefix; | |||||||||||
| 128 | 1 | $prototype .= q{include = }; | |||||||||||
| 129 | 1 | $prototype .= join $SPACE, $configuration->include(); | |||||||||||
| 130 | 1 | $prototype .= "\n"; | |||||||||||
| 131 | |||||||||||||
| 132 | 1 | $prototype .= $prefix; | |||||||||||
| 133 | 1 | $prototype .= q{exclude = }; | |||||||||||
| 134 | 1 | $prototype .= join $SPACE, $configuration->exclude(); | |||||||||||
| 135 | 1 | $prototype .= "\n"; | |||||||||||
| 136 | |||||||||||||
| 137 | 1 | $prototype .= $prefix; | |||||||||||
| 138 | 1 | $prototype .= q{single-transformer = }; | |||||||||||
| 139 | 1 | $prototype .= join $SPACE, $configuration->single_transformer(); | |||||||||||
| 140 | 1 | $prototype .= "\n"; | |||||||||||
| 141 | |||||||||||||
| 142 | 1 | $prototype .= $prefix; | |||||||||||
| 143 | 1 | $prototype .= q{theme = }; | |||||||||||
| 144 | 1 | $prototype .= $configuration->theme()->rule(); | |||||||||||
| 145 | 1 | $prototype .= "\n"; | |||||||||||
| 146 | |||||||||||||
| 147 | 1 | foreach my $item (qw< | |||||||||||
| 148 | color-necessity-highest | ||||||||||||
| 149 | color-necessity-high | ||||||||||||
| 150 | color-necessity-medium | ||||||||||||
| 151 | color-necessity-low | ||||||||||||
| 152 | color-necessity-lowest | ||||||||||||
| 153 | >) { | ||||||||||||
| 154 | 5 | ( my $accessor = $item ) =~ s/ - /_/gmsx; | |||||||||||
| 155 | 5 | $prototype .= $prefix; | |||||||||||
| 156 | 5 | $prototype .= "$item = "; | |||||||||||
| 157 | 5 | $prototype .= $configuration->$accessor; | |||||||||||
| 158 | 5 | $prototype .= "\n"; | |||||||||||
| 159 | } | ||||||||||||
| 160 | |||||||||||||
| 161 | 1 | $prototype .= $prefix; | |||||||||||
| 162 | 1 | $prototype .= q{program-extensions = }; | |||||||||||
| 163 | 1 | $prototype .= join $SPACE, $configuration->program_extensions(); | |||||||||||
| 164 | |||||||||||||
| 165 | 1 | Perl::ToPerl6::Transformer::set_format( $self->_proto_format() ); | |||||||||||
| 166 | |||||||||||||
| 167 | 1 | my $transformer_prototypes = join qq{\n}, map { "$_" } @{ $self->_get_transformers() }; | |||||||||||
| 168 | 1 | $transformer_prototypes =~ s/\s+ \z//xms; # Trim trailing whitespace | |||||||||||
| 169 | 1 | return $prototype . "\n\n" . $transformer_prototypes . "\n"; | |||||||||||
| 170 | } | ||||||||||||
| 171 | |||||||||||||
| 172 | #----------------------------------------------------------------------------- | ||||||||||||
| 173 | |||||||||||||
| 174 | # About "%{\\n%\\x7b# \\x7df\n${prefix}%n = %D\\n}O" below: | ||||||||||||
| 175 | # | ||||||||||||
| 176 | # The %0 format for a transformer specifies how to format parameters. | ||||||||||||
| 177 | # For a parameter %f specifies the full description. | ||||||||||||
| 178 | # | ||||||||||||
| 179 | # The problem is that both of these need to take options, but String::Format | ||||||||||||
| 180 | # doesn't allow nesting of {}. So, to get the option to the %f, the braces | ||||||||||||
| 181 | # are hex encoded. I.e., assuming that comment_out_parameters is in effect, | ||||||||||||
| 182 | # the parameter sees: | ||||||||||||
| 183 | # | ||||||||||||
| 184 | # \n%{# }f\n# %n = %D\n | ||||||||||||
| 185 | |||||||||||||
| 186 | 1 | ▶ | sub _proto_format { | ||||||||||
|
Subroutine
_proto_format: called CC=1 SCAR=0.0
| |||||||||||||
| 187 | 1 | my ($self) = @_; | |||||||||||
| 188 | |||||||||||||
| 189 | 1 | my $prefix = $self->_line_prefix(); | |||||||||||
| 190 | |||||||||||||
| 191 | 1 | return <<"END_OF_FORMAT"; | |||||||||||
| 192 | # %a | ||||||||||||
| 193 | [%p] | ||||||||||||
| 194 | ${prefix}set_themes = %t | ||||||||||||
| 195 | ${prefix}add_themes = | ||||||||||||
| 196 | ${prefix}necessity = %s | ||||||||||||
| 197 | %{\\n%\\x7b# \\x7df\\n${prefix}%n = %D\\n}O%{${prefix}Cannot programmatically discover what parameters this transformer takes.\\n}U | ||||||||||||
| 198 | END_OF_FORMAT | ||||||||||||
| 199 | |||||||||||||
| 200 | } | ||||||||||||
| 201 | |||||||||||||
| 202 | #----------------------------------------------------------------------------- | ||||||||||||
| 203 | |||||||||||||
| 204 | 147 | ▶ | sub _by_type { return ref $a cmp ref $b } | ||||||||||
|
Subroutine
_by_type: called CC=1 SCAR=0.0
| |||||||||||||
| 205 | |||||||||||||
| 206 | 2 | 1; | |||||||||||
| 207 | |||||||||||||
| 208 | __END__ | ||||||||||||