| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Perl::ToPerl6::TransformerConfig; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 13 | use 5.006001; | 
|  | 1 |  |  |  |  | 3 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 16 |  | 
| 5 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 4 | use Readonly; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 4 | use Perl::ToPerl6::Exception::AggregateConfiguration; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 39 |  | 
| 10 | 1 |  |  | 1 |  | 590 | use Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 45 |  | 
| 11 | 1 |  |  | 1 |  | 568 | use Perl::ToPerl6::Exception::Configuration::Option::Transformer::ExtraParameter; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 12 | 1 |  |  | 1 |  | 4 | use Perl::ToPerl6::Utils qw< :booleans :characters necessity_to_number >; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 13 | 1 |  |  | 1 |  | 775 | use Perl::ToPerl6::Utils::Constants qw< :profile_strictness >; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 868 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Readonly::Scalar my $NON_PUBLIC_DATA    => '_non_public_data'; | 
| 18 |  |  |  |  |  |  | Readonly::Scalar my $NO_LIMIT           => 'no_limit'; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub new { | 
| 23 | 81 |  |  | 81 | 0 | 132 | my ($class, $transformer_short_name, $specification) = @_; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 81 | 50 |  |  |  | 144 | my %self = $specification ? %{ $specification } : (); | 
|  | 81 |  |  |  |  | 200 |  | 
| 26 | 81 |  |  |  |  | 93 | my %non_public_data; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 81 |  |  |  |  | 153 | $non_public_data{_transformer_short_name} = $transformer_short_name; | 
| 29 |  |  |  |  |  |  | $non_public_data{_profile_strictness} = | 
| 30 | 81 |  |  |  |  | 173 | $self{$NON_PUBLIC_DATA}{_profile_strictness}; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 81 |  |  |  |  | 125 | foreach my $standard_parameter ( | 
| 33 |  |  |  |  |  |  | qw< necessity set_themes add_themes > | 
| 34 |  |  |  |  |  |  | ) { | 
| 35 | 243 | 50 |  |  |  | 530 | if ( exists $self{$standard_parameter} ) { | 
| 36 |  |  |  |  |  |  | $non_public_data{"_$standard_parameter"} = | 
| 37 | 0 |  |  |  |  | 0 | delete $self{$standard_parameter}; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 81 |  |  |  |  | 133 | $self{$NON_PUBLIC_DATA} = \%non_public_data; | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 81 |  |  |  |  | 269 | return bless \%self, $class; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub _get_non_public_data { | 
| 50 | 111 |  |  | 111 |  | 120 | my $self = shift; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 111 |  |  |  |  | 283 | return $self->{$NON_PUBLIC_DATA}; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub get_transformer_short_name { | 
| 58 | 0 |  |  | 0 | 1 | 0 | my $self = shift; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 0 |  |  |  |  | 0 | return $self->_get_non_public_data()->{_transformer_short_name}; | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | sub get_set_themes { | 
| 66 | 37 |  |  | 37 | 1 | 48 | my ($self) = @_; | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 37 |  |  |  |  | 62 | return $self->_get_non_public_data()->{_set_themes}; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | sub get_add_themes { | 
| 74 | 37 |  |  | 37 | 1 | 45 | my ($self) = @_; | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 37 |  |  |  |  | 60 | return $self->_get_non_public_data()->{_add_themes}; | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub get_necessity { | 
| 82 | 37 |  |  | 37 | 1 | 54 | my ($self) = @_; | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 37 |  |  |  |  | 78 | return $self->_get_non_public_data()->{_necessity}; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | sub get { | 
| 90 | 0 |  |  | 0 | 1 | 0 | my ($self, $parameter) = @_; | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 0 | 0 |  |  |  | 0 | return if $parameter eq $NON_PUBLIC_DATA; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 0 |  |  |  |  | 0 | return $self->{$parameter}; | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | sub remove { | 
| 100 | 1 |  |  | 1 | 1 | 2 | my ($self, $parameter) = @_; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 1 | 50 |  |  |  | 5 | return if $parameter eq $NON_PUBLIC_DATA; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 1 |  |  |  |  | 2 | delete $self->{$parameter}; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 1 |  |  |  |  | 4 | return; | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub is_empty { | 
| 112 | 0 |  |  | 0 | 1 | 0 | my ($self) = @_; | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  | 0 | return 1 >= keys %{$self}; | 
|  | 0 |  |  |  |  | 0 |  | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | sub get_parameter_names { | 
| 120 | 43 |  |  | 43 | 1 | 61 | my ($self) = @_; | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 43 |  |  |  |  | 52 | return grep { $_ ne $NON_PUBLIC_DATA } keys %{$self}; | 
|  | 43 |  |  |  |  | 160 |  | 
|  | 43 |  |  |  |  | 97 |  | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | sub handle_extra_parameters { | 
| 128 | 43 |  |  | 43 | 1 | 61 | my ($self, $transformer, $errors) = @_; | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 43 |  |  |  |  | 91 | my $profile_strictness = $self->{$NON_PUBLIC_DATA}{_profile_strictness}; | 
| 131 | 43 | 100 |  |  |  | 89 | defined $profile_strictness | 
| 132 |  |  |  |  |  |  | or $profile_strictness = $PROFILE_STRICTNESS_DEFAULT; | 
| 133 |  |  |  |  |  |  |  | 
| 134 | 43 | 50 |  |  |  | 87 | return if $profile_strictness eq $PROFILE_STRICTNESS_QUIET; | 
| 135 |  |  |  |  |  |  |  | 
| 136 | 43 | 50 |  |  |  | 167 | my $parameter_errors = $profile_strictness eq $PROFILE_STRICTNESS_WARN ? | 
| 137 |  |  |  |  |  |  | Perl::ToPerl6::Exception::AggregateConfiguration->new() : $errors; | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 43 |  |  |  |  | 21936 | foreach my $offered_param ( $self->get_parameter_names() ) { | 
| 140 | 0 |  |  |  |  | 0 | $parameter_errors->add_exception( | 
| 141 |  |  |  |  |  |  | Perl::ToPerl6::Exception::Configuration::Option::Transformer::ExtraParameter->new( | 
| 142 |  |  |  |  |  |  | transformer => $transformer->get_short_name(), | 
| 143 |  |  |  |  |  |  | option_name => $offered_param, | 
| 144 |  |  |  |  |  |  | source  => undef, | 
| 145 |  |  |  |  |  |  | ) | 
| 146 |  |  |  |  |  |  | ); | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 | 43 | 50 | 33 |  |  | 191 | warn qq<$parameter_errors\n> | 
| 150 |  |  |  |  |  |  | if ($profile_strictness eq $PROFILE_STRICTNESS_WARN | 
| 151 |  |  |  |  |  |  | && $parameter_errors->has_exceptions()); | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 43 |  |  |  |  | 1114 | return; | 
| 154 |  |  |  |  |  |  | } | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | sub set_profile_strictness { | 
| 159 | 37 |  |  | 37 | 1 | 48 | my ($self, $profile_strictness) = @_; | 
| 160 |  |  |  |  |  |  |  | 
| 161 | 37 |  |  |  |  | 68 | $self->{$NON_PUBLIC_DATA}{_profile_strictness} = $profile_strictness; | 
| 162 |  |  |  |  |  |  |  | 
| 163 | 37 |  |  |  |  | 71 | return; | 
| 164 |  |  |  |  |  |  | } | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | 1; | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | __END__ | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | #----------------------------------------------------------------------------- | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =pod | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =for stopwords | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | =head1 NAME | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | Perl::ToPerl6::TransformerConfig - Configuration data for a Transformer. | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | A container for the configuration of a Transformer. | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head1 INTERFACE SUPPORT | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | This is considered to be a non-public class.  Its interface is subject | 
| 192 |  |  |  |  |  |  | to change without notice. | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 METHODS | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =over | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =item C<get_transformer_short_name()> | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | The name of the transformer this configuration is for.  Primarily here for | 
| 202 |  |  |  |  |  |  | the sake of debugging. | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | =item C< get_set_themes() > | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | The value of C<set_themes> in the user's F<.perlmogrifyrc>. | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | =item C< get_add_themes() > | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | The value of C<add_themes> in the user's F<.perlmogrifyrc>. | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | =item C< get_necessity() > | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | The value of C<necessity> in the user's F<.perlmogrifyrc>. | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | =item C< get($parameter) > | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | Retrieve the value of the specified parameter in the user's | 
| 223 |  |  |  |  |  |  | F<.perlmogrifyrc>. | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | =item C< remove($parameter) > | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | Delete the value of the specified parameter. | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  |  | 
| 231 |  |  |  |  |  |  | =item C< is_empty() > | 
| 232 |  |  |  |  |  |  |  | 
| 233 |  |  |  |  |  |  | Answer whether there is any non-standard configuration information | 
| 234 |  |  |  |  |  |  | left. | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  |  | 
| 237 |  |  |  |  |  |  | =item C< get_parameter_names() > | 
| 238 |  |  |  |  |  |  |  | 
| 239 |  |  |  |  |  |  | Retrieve the names of the parameters in this object. | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | =item C< set_profile_strictness($profile_strictness) > | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | Sets the profile strictness associated with the configuration. | 
| 245 |  |  |  |  |  |  |  | 
| 246 |  |  |  |  |  |  |  | 
| 247 |  |  |  |  |  |  | =item C< handle_extra_parameters($transformer,$errors) > | 
| 248 |  |  |  |  |  |  |  | 
| 249 |  |  |  |  |  |  | Deals with any extra parameters according to the profile_strictness | 
| 250 |  |  |  |  |  |  | setting.  To be called by Perl::ToPerl6::Transformer->new() once all valid | 
| 251 |  |  |  |  |  |  | transformers have been processed and removed from the configuration. | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | If profile_strictness is $PROFILE_STRICTNESS_QUIET, extra transformer | 
| 254 |  |  |  |  |  |  | parameters are ignored. | 
| 255 |  |  |  |  |  |  |  | 
| 256 |  |  |  |  |  |  | If profile_strictness is $PROFILE_STRICTNESS_WARN, extra transformer | 
| 257 |  |  |  |  |  |  | parameters generate a warning. | 
| 258 |  |  |  |  |  |  |  | 
| 259 |  |  |  |  |  |  | If profile_strictness is $PROFILE_STRICTNESS_FATAL, extra transformer | 
| 260 |  |  |  |  |  |  | parameters generate a fatal error. | 
| 261 |  |  |  |  |  |  |  | 
| 262 |  |  |  |  |  |  | If no profile_strictness was set, the behavior is that specified by | 
| 263 |  |  |  |  |  |  | $PROFILE_STRICTNESS_DEFAULT. | 
| 264 |  |  |  |  |  |  |  | 
| 265 |  |  |  |  |  |  |  | 
| 266 |  |  |  |  |  |  | =back | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  |  | 
| 269 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 270 |  |  |  |  |  |  |  | 
| 271 |  |  |  |  |  |  | L<Perl::ToPerl6::DEVELOPER/"MAKING YOUR TRANSFORMER CONFIGURABLE"> | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  |  | 
| 274 |  |  |  |  |  |  | =head1 AUTHOR | 
| 275 |  |  |  |  |  |  |  | 
| 276 |  |  |  |  |  |  | Elliot Shank <perl@galumph.com> | 
| 277 |  |  |  |  |  |  |  | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 280 |  |  |  |  |  |  |  | 
| 281 |  |  |  |  |  |  | Copyright (c) 2008-2011 Elliot Shank. | 
| 282 |  |  |  |  |  |  |  | 
| 283 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify | 
| 284 |  |  |  |  |  |  | it under the same terms as Perl itself.  The full text of this license | 
| 285 |  |  |  |  |  |  | can be found in the LICENSE file included with this module. | 
| 286 |  |  |  |  |  |  |  | 
| 287 |  |  |  |  |  |  | =cut | 
| 288 |  |  |  |  |  |  |  | 
| 289 |  |  |  |  |  |  | # Local Variables: | 
| 290 |  |  |  |  |  |  | #   mode: cperl | 
| 291 |  |  |  |  |  |  | #   cperl-indent-level: 4 | 
| 292 |  |  |  |  |  |  | #   fill-column: 78 | 
| 293 |  |  |  |  |  |  | #   indent-tabs-mode: nil | 
| 294 |  |  |  |  |  |  | #   c-indentation-style: bsd | 
| 295 |  |  |  |  |  |  | # End: | 
| 296 |  |  |  |  |  |  | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |