File Coverage

blib/lib/Perl/ToPerl6/Transformer.pm
Criterion Covered Total %
statement 185 213 86.8
branch 22 36 61.1
condition 2 3 66.6
subroutine 64 70 91.4
pod 28 29 96.5
total 301 351 85.7


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Transformer;
2              
3 23     23   62382 use 5.006001;
  23         65  
4 23     23   104 use strict;
  23         36  
  23         535  
5 23     23   98 use warnings;
  23         42  
  23         725  
6              
7 23     23   98 use English qw< -no_match_vars >;
  23         41  
  23         151  
8 23     23   12603 use Readonly;
  23         17734  
  23         1162  
9              
10 23     23   120 use File::Spec ();
  23         33  
  23         490  
11 23     23   12472 use String::Format qw< stringf >;
  23         15184  
  23         1568  
12              
13 23     23   7251 use overload ( q<""> => 'to_string', cmp => '_compare' );
  23         5867  
  23         183  
14              
15 23         1223 use Perl::ToPerl6::Utils qw<
16             :characters
17             :booleans
18             :severities
19             :data_conversion
20             interpolate
21             is_integer
22             transformer_long_name
23             transformer_short_name
24             severity_to_number
25 23     23   5609 >;
  23         41  
26 23     23   18163 use Perl::ToPerl6::Utils::DataConversion qw< dor >;
  23         58  
  23         615  
27 23         1976 use Perl::ToPerl6::Utils::POD qw<
28             get_module_abstract_for_module
29             get_raw_module_abstract_for_module
30 23     23   12111 >;
  23         64  
31 23     23   2995 use Perl::ToPerl6::Exception::AggregateConfiguration;
  23         39  
  23         922  
32 23     23   2383 use Perl::ToPerl6::Exception::Configuration;
  23         44  
  23         852  
33 23     23   3121 use Perl::ToPerl6::Exception::Configuration::Option::Transformer::ExtraParameter;
  23         35  
  23         937  
34 23     23   2762 use Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue;
  23         40  
  23         1008  
35             use Perl::ToPerl6::Exception::Fatal::TransformerDefinition
36 23     23   2796 qw< throw_transformer_definition >;
  23         34  
  23         873  
37 23     23   2840 use Perl::ToPerl6::TransformerConfig qw<>;
  23         37  
  23         394  
38 23     23   10791 use Perl::ToPerl6::TransformerParameter qw<>;
  23         64  
  23         821  
39 23     23   10502 use Perl::ToPerl6::Transformation qw<>;
  23         52  
  23         608  
40              
41 23     23   129 use Exception::Class; # this must come after "use P::C::Exception::*"
  23         32  
  23         183  
42              
43             our $VERSION = '0.03';
44              
45             #-----------------------------------------------------------------------------
46              
47             Readonly::Scalar my $NO_LIMIT => 'no_limit';
48              
49             #-----------------------------------------------------------------------------
50              
51             my $format = "%p\n"; #Default stringy format
52              
53             #-----------------------------------------------------------------------------
54              
55             sub new {
56 1508     1508 1 327904 my ($class, %config) = @_;
57              
58 1508         2715 my $self = bless {}, $class;
59              
60 1508         1638 my $config_object;
61 1508 50       2829 if ($config{_config_object}) {
62 0         0 $config_object = $config{_config_object};
63             }
64             else {
65 1508         4257 $config_object =
66             Perl::ToPerl6::TransformerConfig->new(
67             $self->get_short_name(),
68             \%config,
69             );
70             }
71              
72 1508         4822 $self->__set_config( $config_object );
73              
74 1508         1271 my @parameters;
75 1508         1545 my $parameter_metadata_available = 0;
76              
77 1508 100       13184 if ( $class->can('supported_parameters') ) {
78 1449         1478 $parameter_metadata_available = 1;
79             @parameters =
80             map
81 1449         6308 { Perl::ToPerl6::TransformerParameter->new($_) }
  0         0  
82             $class->supported_parameters();
83             }
84 1508         2516 $self->{_parameter_metadata_available} = $parameter_metadata_available;
85 1508         2223 $self->{_parameters} = \@parameters;
86              
87 1508         5381 my $errors = Perl::ToPerl6::Exception::AggregateConfiguration->new();
88 1508         648087 foreach my $parameter ( @parameters ) {
89             eval {
90 0         0 $parameter->parse_and_validate_config_value( $self, $config_object );
91             }
92 0 0       0 or do {
93 0         0 $errors->add_exception_or_rethrow($EVAL_ERROR);
94             };
95              
96 0         0 $config_object->remove( $parameter->get_name() );
97             }
98              
99 1508 100       3528 if ($parameter_metadata_available) {
100 1449         4914 $config_object->handle_extra_parameters( $self, $errors );
101             }
102              
103 1508 100       4134 if ( $errors->has_exceptions() ) {
104 38         329 $errors->rethrow();
105             }
106              
107 1470         37418 return $self;
108             }
109              
110             #-----------------------------------------------------------------------------
111              
112             sub is_safe {
113 1025     1025 1 21201 return $TRUE;
114             }
115              
116             #-----------------------------------------------------------------------------
117              
118             sub initialize_if_enabled {
119 880     880 1 2116 return $TRUE;
120             }
121              
122             #-----------------------------------------------------------------------------
123              
124             sub prepare_to_scan_document {
125 151     151 1 365 return $TRUE;
126             }
127              
128             #-----------------------------------------------------------------------------
129              
130             sub __get_parameter_name {
131 49     49   58 my ( $self, $parameter ) = @_;
132              
133 49         124 return '_' . $parameter->get_name();
134             }
135              
136             #-----------------------------------------------------------------------------
137              
138             sub __set_parameter_value {
139 49     49   58 my ( $self, $parameter, $value ) = @_;
140              
141 49         103 $self->{ $self->__get_parameter_name($parameter) } = $value;
142              
143 49         98 return;
144             }
145              
146             #-----------------------------------------------------------------------------
147              
148             sub __set_base_parameters {
149 1371     1371   1658 my ($self) = @_;
150              
151 1371         3340 my $config = $self->__get_config();
152 1371         4993 my $errors = Perl::ToPerl6::Exception::AggregateConfiguration->new();
153              
154 1371         607573 $self->_set_maximum_transformations_per_document($errors);
155              
156 1371         3056 my $user_severity = $config->get_severity();
157 1371 100       3080 if ( defined $user_severity ) {
158 47         228 my $normalized_severity = severity_to_number( $user_severity );
159 46         400 $self->set_severity( $normalized_severity );
160             }
161              
162 1370         3109 my $user_set_themes = $config->get_set_themes();
163 1370 100       2477 if ( defined $user_set_themes ) {
164 40         161 my @set_themes = words_from_string( $user_set_themes );
165 40         236 $self->set_themes( @set_themes );
166             }
167              
168 1370         3036 my $user_add_themes = $config->get_add_themes();
169 1370 100       2563 if ( defined $user_add_themes ) {
170 43         251 my @add_themes = words_from_string( $user_add_themes );
171 43         243 $self->add_themes( @add_themes );
172             }
173              
174 1370 50       3668 if ( $errors->has_exceptions() ) {
175 0         0 $errors->rethrow();
176             }
177              
178 1370         36005 return;
179             }
180              
181             #-----------------------------------------------------------------------------
182              
183             sub _set_maximum_transformations_per_document {
184 1371     1371   1951 my ($self, $errors) = @_;
185              
186 1371         2602 my $config = $self->__get_config();
187              
188 1371 50       4375 if ( $config->is_maximum_transformations_per_document_unlimited() ) {
189 1371         1728 return;
190             }
191              
192 0         0 my $user_maximum_transformations =
193             $config->get_maximum_transformations_per_document();
194              
195 0 0       0 if ( not is_integer($user_maximum_transformations) ) {
    0          
196 0         0 $errors->add_exception(
197             new_parameter_value_exception(
198             'maximum_transformations_per_document',
199             $user_maximum_transformations,
200             undef,
201             "does not look like an integer.\n"
202             )
203             );
204              
205 0         0 return;
206             }
207             elsif ( $user_maximum_transformations < 0 ) {
208 0         0 $errors->add_exception(
209             new_parameter_value_exception(
210             'maximum_transformations_per_document',
211             $user_maximum_transformations,
212             undef,
213             "is not greater than or equal to zero.\n"
214             )
215             );
216              
217 0         0 return;
218             }
219              
220             $self->set_maximum_transformations_per_document(
221 0         0 $user_maximum_transformations
222             );
223              
224 0         0 return;
225             }
226              
227             #-----------------------------------------------------------------------------
228              
229             # Unparsed configuration, P::C::TransformerConfig. Compare with get_parameters().
230             sub __get_config {
231 3622     3622   3458 my ($self) = @_;
232              
233 3622         6918 return $self->{_config};
234             }
235              
236             sub __set_config {
237 2879     2879   3352 my ($self, $config) = @_;
238              
239 2879         20738 $self->{_config} = $config;
240              
241 2879         6245 return;
242             }
243              
244             #-----------------------------------------------------------------------------
245              
246             sub get_long_name {
247 0     0 1 0 my ($self) = @_;
248              
249 0         0 return transformer_long_name(ref $self);
250             }
251              
252             #-----------------------------------------------------------------------------
253              
254             sub get_short_name {
255 12312     12312 1 12704 my ($self) = @_;
256              
257 12312         33865 return transformer_short_name(ref $self);
258             }
259              
260             #-----------------------------------------------------------------------------
261              
262             sub is_enabled {
263 2     2 1 746 my ($self) = @_;
264              
265 2         9 return $self->{_enabled};
266             }
267              
268             #-----------------------------------------------------------------------------
269              
270             sub __set_enabled {
271 880     880   894 my ($self, $new_value) = @_;
272              
273 880         1406 $self->{_enabled} = $new_value;
274              
275 880         1445 return;
276             }
277              
278             #-----------------------------------------------------------------------------
279              
280             sub applies_to {
281 1     1 1 5 return qw(PPI::Element);
282             }
283              
284             #-----------------------------------------------------------------------------
285              
286             sub set_maximum_transformations_per_document {
287 2     2 1 425 my ($self, $maximum_transformations_per_document) = @_;
288              
289             $self->{_maximum_transformations_per_document} =
290 2         5 $maximum_transformations_per_document;
291              
292 2         3 return $self;
293             }
294              
295             #-----------------------------------------------------------------------------
296              
297             sub get_maximum_transformations_per_document {
298 497     497 1 1002 my ($self) = @_;
299              
300             return
301             exists $self->{_maximum_transformations_per_document}
302             ? $self->{_maximum_transformations_per_document}
303 497 100       1911 : $self->default_maximum_transformations_per_document();
304             }
305              
306             #-----------------------------------------------------------------------------
307              
308             sub default_maximum_transformations_per_document {
309 496     496 1 1353 return;
310             }
311              
312             #-----------------------------------------------------------------------------
313              
314             sub set_severity {
315 47     47 1 85 my ($self, $severity) = @_;
316 47         468 $self->{_severity} = $severity;
317 47         94 return $self;
318             }
319              
320             #-----------------------------------------------------------------------------
321              
322             sub get_severity {
323 1391     1391 1 2051 my ($self) = @_;
324 1391   66     7511 return $self->{_severity} || $self->default_severity();
325             }
326              
327             #-----------------------------------------------------------------------------
328              
329             sub default_severity {
330 3     3 1 15 return $SEVERITY_LOWEST;
331             }
332              
333             #-----------------------------------------------------------------------------
334              
335             sub set_themes {
336 41     41 1 98 my ($self, @themes) = @_;
337 41         204 $self->{_themes} = [ sort @themes ];
338 41         100 return $self;
339             }
340              
341             #-----------------------------------------------------------------------------
342              
343             sub get_themes {
344 1268     1268 1 2268 my ($self) = @_;
345 1268 100       5267 my @themes = defined $self->{_themes} ? @{ $self->{_themes} } : $self->default_themes();
  316         791  
346 1268         3550 my @sorted_themes = sort @themes;
347 1268         4788 return @sorted_themes;
348             }
349              
350             #-----------------------------------------------------------------------------
351              
352             sub add_themes {
353 44     44 1 86 my ($self, @additional_themes) = @_;
354             #By hashifying the themes, we squish duplicates
355 44         151 my %merged = hashify( $self->get_themes(), @additional_themes);
356 44         183 $self->{_themes} = [ keys %merged];
357 44         143 return $self;
358             }
359              
360             #-----------------------------------------------------------------------------
361              
362             sub default_themes {
363 4     4 1 16 return ();
364             }
365              
366             #-----------------------------------------------------------------------------
367              
368             sub get_abstract {
369 342     342 1 361 my ($self) = @_;
370              
371 342         994 return get_module_abstract_for_module( ref $self );
372             }
373              
374             #-----------------------------------------------------------------------------
375              
376             sub get_raw_abstract {
377 0     0 1 0 my ($self) = @_;
378              
379 0         0 return get_raw_module_abstract_for_module( ref $self );
380             }
381              
382             #-----------------------------------------------------------------------------
383              
384             sub parameter_metadata_available {
385 722     722 1 853 my ($self) = @_;
386              
387 722         2201 return $self->{_parameter_metadata_available};
388             }
389              
390             #-----------------------------------------------------------------------------
391              
392             sub get_parameters {
393 379     379 1 735 my ($self) = @_;
394              
395 379         1328 return $self->{_parameters};
396             }
397              
398             #-----------------------------------------------------------------------------
399              
400             sub transform {
401 1     1 0 715 my ($self) = @_;
402              
403 1         4 return throw_transformer_definition(
404             $self->get_short_name() . q/ does not implement transform()./ );
405             }
406              
407             #-----------------------------------------------------------------------------
408              
409             sub transformation {
410 19     19 1 44 my ( $self, $desc, $expl, $elem ) = @_;
411             # HACK!! Use goto instead of an explicit call because P::C::V::new() uses caller()
412 19         45 my $sev = $self->get_severity();
413 19         78 @_ = ('Perl::ToPerl6::Transformation', $desc, $expl, $elem, $sev );
414 19         93 goto &Perl::ToPerl6::Transformation::new;
415             }
416              
417             #-----------------------------------------------------------------------------
418              
419             sub new_parameter_value_exception {
420 7     7 1 8 my ( $self, $option_name, $option_value, $source, $message_suffix ) = @_;
421              
422 7         14 return Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue->new(
423             transformer => $self->get_short_name(),
424             option_name => $option_name,
425             option_value => $option_value,
426             source => $source,
427             message_suffix => $message_suffix
428             );
429             }
430              
431             #-----------------------------------------------------------------------------
432              
433             sub throw_parameter_value_exception {
434 7     7 1 11 my ( $self, $option_name, $option_value, $source, $message_suffix ) = @_;
435              
436 7         15 $self->new_parameter_value_exception(
437             $option_name, $option_value, $source, $message_suffix
438             )
439             ->throw();
440             }
441             ## use mogrify
442              
443              
444             #-----------------------------------------------------------------------------
445              
446             # Static methods.
447              
448 3     3 1 12 sub set_format { return $format = $_[0] }
449 10758     10758 1 39815 sub get_format { return $format }
450              
451             #-----------------------------------------------------------------------------
452              
453             sub to_string {
454 10756     10756 1 147367 my ($self, @args) = @_;
455              
456             # Wrap the more expensive ones in sub{} to postpone evaluation
457             my %fspec = (
458 0     0   0 'P' => sub { $self->get_long_name() },
459 10756     10756   330594 'p' => sub { $self->get_short_name() },
460 342     342   11868 'a' => sub { dor($self->get_abstract(), $EMPTY) },
461 342     342   7409 'O' => sub { $self->_format_parameters(@_) },
462 342     342   7378 'U' => sub { $self->_format_lack_of_parameter_metadata(@_) },
463 0     0   0 'S' => sub { $self->default_severity() },
464 382     382   8910 's' => sub { $self->get_severity() },
465 0     0   0 'T' => sub { join $SPACE, $self->default_themes() },
466 382     382   8494 't' => sub { join $SPACE, $self->get_themes() },
467 0     0   0 'V' => sub { dor( $self->default_maximum_transformations_per_document(), $NO_LIMIT ) },
468 342     342   6993 'v' => sub { dor( $self->get_maximum_transformations_per_document(), $NO_LIMIT ) },
469 10756         126147 );
470 10756         19004 return stringf(get_format(), %fspec);
471             }
472              
473             sub _format_parameters {
474 342     342   457 my ($self, $parameter_format) = @_;
475              
476 342 50       845 return $EMPTY if not $self->parameter_metadata_available();
477              
478 342         357 my $separator;
479 342 50       546 if ($parameter_format) {
480 342         406 $separator = $EMPTY;
481             } else {
482 0         0 $separator = $SPACE;
483 0         0 $parameter_format = '%n';
484             }
485              
486             return
487             join
488             $separator,
489 342         306 map { $_->to_formatted_string($parameter_format) } @{ $self->get_parameters() };
  0         0  
  342         801  
490             }
491              
492             sub _format_lack_of_parameter_metadata {
493 342     342   470 my ($self, $message) = @_;
494              
495 342 50       534 return $EMPTY if $self->parameter_metadata_available();
496 0 0       0 return interpolate($message) if $message;
497              
498             return
499 0         0 'Cannot programmatically discover what parameters this transformer takes.';
500             }
501              
502             #-----------------------------------------------------------------------------
503             # Apparently, some perls do not implicitly stringify overloading
504             # objects before doing a comparison. This causes a couple of our
505             # sorting tests to fail. To work around this, we overload C<cmp> to
506             # do it explicitly.
507             #
508             # 20060503 - More information: This problem has been traced to
509             # Test::Simple versions <= 0.60, not perl itself. Upgrading to
510             # Test::Simple v0.62 will fix the problem. But rather than forcing
511             # everyone to upgrade, I have decided to leave this workaround in
512             # place.
513              
514 162     162   2969 sub _compare { return "$_[0]" cmp "$_[1]" }
515              
516             1;
517              
518             __END__
519              
520             #-----------------------------------------------------------------------------
521              
522             =pod
523              
524             =head1 NAME
525              
526             Perl::ToPerl6::Transformer - Base class for all Transformer modules.
527              
528              
529             =head1 DESCRIPTION
530              
531             Perl::ToPerl6::Transformer is the abstract base class for all Transformer
532             objects. If you're developing your own Transformers, your job is to
533             implement and override its methods in a subclass. To work with the
534             L<Perl::ToPerl6|Perl::ToPerl6> engine, your implementation must behave
535             as described below. For a detailed explanation on how to make new
536             Transformer modules, please see the
537             L<Perl::ToPerl6::DEVELOPER|Perl::ToPerl6::DEVELOPER> document included
538             in this distribution.
539              
540              
541             =head1 INTERFACE SUPPORT
542              
543             This is considered to be a public class. Any changes to its interface
544             will go through a deprecation cycle.
545              
546              
547             =head1 METHODS
548              
549             =over
550              
551             =item C<< new( ... ) >>
552              
553             Don't call this. As a Transformer author, do not implement this. Use the
554             C<initialize_if_enabled()> method for your Transformer setup. See the
555             L<developer|Perl::ToPerl6::DEVELOPER> documentation for more.
556              
557              
558             =item C<< initialize_if_enabled( $config ) >>
559              
560             This receives an instance of
561             L<Perl::ToPerl6::TransformerConfig|Perl::ToPerl6::TransformerConfig> as a
562             parameter, and is only invoked if this Transformer is enabled by the user.
563             Thus, this is the preferred place for subclasses to do any
564             initialization.
565              
566             Implementations of this method should return a boolean value
567             indicating whether the Transformer should continue to be enabled. For most
568             subclasses, this will always be C<$TRUE>. Transformers that depend upon
569             external modules or other system facilities that may or may not be
570             available should test for the availability of these dependencies and
571             return C<$FALSE> if they are not.
572              
573              
574             =item C<< prepare_to_scan_document( $document ) >>
575              
576             The parameter is about to be scanned by this Transformer. Whatever this
577             Transformer wants to do in terms of preparation should happen here.
578             Returns a boolean value indicating whether the document should be
579             scanned at all; if this is a false value, this Transformer won't be applied
580             to the document. By default, does nothing but return C<$TRUE>.
581              
582              
583             =item C< violates( $element, $document ) >
584              
585             Given a L<PPI::Element|PPI::Element> and a
586             L<PPI::Document|PPI::Document>, returns one or more
587             L<Perl::ToPerl6::Transformation|Perl::ToPerl6::Transformation> objects if the
588             C<$element> violates this Transformer. If there are no transformations, then it
589             returns an empty list. If the Transformer encounters an exception, then it
590             should C<croak> with an error message and let the caller decide how to
591             handle it.
592              
593             C<transform()> is an abstract method and it will abort if you attempt
594             to invoke it directly. It is the heart of all Transformer modules, and
595             your subclass B<must> override this method.
596              
597              
598             =item C< transformation( $description, $explanation, $element ) >
599              
600             Returns a reference to a new C<Perl::ToPerl6::Transformation> object. The
601             arguments are a description of the transformation (as string), an
602             explanation for the transformer (as string) or a series of page numbers in
603             PBP (as an ARRAY ref), a reference to the L<PPI|PPI> element that
604             caused the transformation.
605              
606             These are the same as the constructor to
607             L<Perl::ToPerl6::Transformation|Perl::ToPerl6::Transformation>, but without the
608             severity. The Transformer itself knows the severity.
609              
610              
611             =item C< new_parameter_value_exception( $option_name, $option_value, $source, $message_suffix ) >
612              
613             Create a
614             L<Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue|Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue>
615             for this Transformer.
616              
617              
618             =item C< throw_parameter_value_exception( $option_name, $option_value, $source, $message_suffix ) >
619              
620             Create and throw a
621             L<Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue|Perl::ToPerl6::Exception::Configuration::Option::Transformer::ParameterValue>.
622             Useful in parameter parser implementations.
623              
624              
625             =item C< get_long_name() >
626              
627             Return the full package name of this transformer.
628              
629              
630             =item C< get_short_name() >
631              
632             Return the name of this transformer without the "Perl::ToPerl6::Transformer::"
633             prefix.
634              
635              
636             =item C< is_enabled() >
637              
638             Answer whether this transformer is really active or not. Returns a true
639             value if it is, a false, yet defined, value if it isn't, and an
640             undefined value if it hasn't yet been decided whether it will be.
641              
642              
643             =item C< applies_to() >
644              
645             Returns a list of the names of PPI classes that this Transformer cares
646             about. By default, the result is C<PPI::Element>. Overriding this
647             method in Transformer subclasses should lead to significant performance
648             increases.
649              
650              
651             =item C< default_maximum_transformations_per_document() >
652              
653             Returns the default maximum number of transformations for this transformer to
654             report per document. By default, this not defined, but subclasses may
655             override this.
656              
657              
658             =item C< get_maximum_transformations_per_document() >
659              
660             Returns the maximum number of transformations this transformer will report for a
661             single document. If this is not defined, then there is no limit. If
662             L</set_maximum_transformations_per_document()> has not been invoked, then
663             L</default_maximum_transformations_per_document()> is returned.
664              
665              
666             =item C< set_maximum_transformations_per_document() >
667              
668             Specify the maximum transformations that this transformer should report for a
669             document.
670              
671              
672             =item C< default_severity() >
673              
674             Returns the default severity for violating this Transformer. See the
675             C<$SEVERITY> constants in L<Perl::ToPerl6::Utils|Perl::ToPerl6::Utils>
676             for an enumeration of possible severity values. By default, this
677             method returns C<$SEVERITY_LOWEST>. Authors of Perl::ToPerl6::Transformer
678             subclasses should override this method to return a value that they
679             feel is appropriate for their Transformer. In general, Polices that are
680             widely accepted or tend to prevent bugs should have a higher severity
681             than those that are more subjective or cosmetic in nature.
682              
683              
684             =item C< get_severity() >
685              
686             Returns the severity of violating this Transformer. If the severity has
687             not been explicitly defined by calling C<set_severity>, then the
688             C<default_severity> is returned. See the C<$SEVERITY> constants in
689             L<Perl::ToPerl6::Utils|Perl::ToPerl6::Utils> for an enumeration of
690             possible severity values.
691              
692              
693             =item C< set_severity( $N ) >
694              
695             Sets the severity for violating this Transformer. Clients of
696             Perl::ToPerl6::Transformer objects can call this method to assign a
697             different severity to the Transformer if they don't agree with the
698             C<default_severity>. See the C<$SEVERITY> constants in
699             L<Perl::ToPerl6::Utils|Perl::ToPerl6::Utils> for an enumeration of
700             possible values.
701              
702              
703             =item C< default_themes() >
704              
705             Returns a sorted list of the default themes associated with this
706             Transformer. The default method returns an empty list. Transformer authors
707             should override this method to return a list of themes that are
708             appropriate for their transformer.
709              
710              
711             =item C< get_themes() >
712              
713             Returns a sorted list of the themes associated with this Transformer. If
714             you haven't added themes or set the themes explicitly, this method
715             just returns the default themes.
716              
717              
718             =item C< set_themes( @THEME_LIST ) >
719              
720             Sets the themes associated with this Transformer. Any existing themes are
721             overwritten. Duplicate themes will be removed.
722              
723              
724             =item C< add_themes( @THEME_LIST ) >
725              
726             Appends additional themes to this Transformer. Any existing themes are
727             preserved. Duplicate themes will be removed.
728              
729              
730             =item C< get_abstract() >
731              
732             Retrieve the abstract for this transformer (the part of the NAME section of
733             the POD after the module name), if it is available.
734              
735              
736             =item C< get_raw_abstract() >
737              
738             Retrieve the abstract for this transformer (the part of the NAME section of
739             the POD after the module name), if it is available, in the unparsed
740             form.
741              
742              
743             =item C< parameter_metadata_available() >
744              
745             Returns whether information about the parameters is available.
746              
747              
748             =item C< get_parameters() >
749              
750             Returns a reference to an array containing instances of
751             L<Perl::ToPerl6::TransformerParameter|Perl::ToPerl6::TransformerParameter>.
752              
753             Note that this will return an empty list if the parameters for this
754             transformer are unknown. In order to differentiate between this
755             circumstance and the one where this transformer does not take any
756             parameters, it is necessary to call C<parameter_metadata_available()>.
757              
758              
759             =item C<set_format( $format )>
760              
761             Class method. Sets the format for all Transformer objects when they are
762             evaluated in string context. The default is C<"%p\n">. See
763             L<"OVERLOADS"> for formatting options.
764              
765              
766             =item C<get_format()>
767              
768             Class method. Returns the current format for all Transformer objects when
769             they are evaluated in string context.
770              
771              
772             =item C<to_string()>
773              
774             Returns a string representation of the transformer. The content of the
775             string depends on the current value returned by C<get_format()>.
776             See L<"OVERLOADS"> for the details.
777              
778              
779             =item C<is_safe()>
780              
781             Answer whether this Transformer can be used to analyze untrusted code, i.e. the
782             Transformer doesn't have any potential side effects.
783              
784             This method returns a true value by default.
785              
786             An "unsafe" transformer might attempt to compile the code, which, if you have
787             C<BEGIN> or C<CHECK> blocks that affect files or connect to databases, is not
788             a safe thing to do. If you are writing a such a Transformer, then you should
789             override this method to return false.
790              
791             By default L<Perl::ToPerl6|Perl::ToPerl6> will not run unsafe transformers.
792              
793              
794              
795             =back
796              
797              
798             =head1 DOCUMENTATION
799              
800             When your Transformer module first C<use>s
801             L<Perl::ToPerl6::Transformation|Perl::ToPerl6::Transformation>, it will try and
802             extract the DESCRIPTION section of your Transformer module's POD. This
803             information is displayed by Perl::ToPerl6 if the verbosity level is set
804             accordingly. Therefore, please include a DESCRIPTION section in the
805             POD for any Transformer modules that you author. Thanks.
806              
807              
808             =head1 OVERLOADS
809              
810             Perl::ToPerl6::Transformation overloads the C<""> operator to produce neat
811             little messages when evaluated in string context.
812              
813             Formats are a combination of literal and escape characters similar to
814             the way C<sprintf> works. If you want to know the specific formatting
815             capabilities, look at L<String::Format|String::Format>. Valid escape
816             characters are:
817              
818              
819             =over
820              
821             =item C<%P>
822              
823             Name of the Transformer module.
824              
825              
826             =item C<%p>
827              
828             Name of the Transformer without the C<Perl::ToPerl6::Transformer::> prefix.
829              
830              
831             =item C<%a>
832              
833             The transformer abstract.
834              
835              
836             =item C<%O>
837              
838             List of supported transformer parameters. Takes an option of a format
839             string for L<Perl::ToPerl6::TransformerParameter/"to_formatted_string">.
840             For example, this can be used like C<%{%n - %d\n}O> to get a list of
841             parameter names followed by their descriptions.
842              
843              
844             =item C<%U>
845              
846             A message stating that the parameters for the transformer are unknown if
847             C<parameter_metadata_available()> returns false. Takes an option of
848             what the message should be, which defaults to "Cannot programmatically
849             discover what parameters this transformer takes.". The value of this
850             option is interpolated in order to expand the standard escape
851             sequences (C<\n>, C<\t>, etc.).
852              
853              
854             =item C<%S>
855              
856             The default severity level of the transformer.
857              
858              
859             =item C<%s>
860              
861             The current severity level of the transformer.
862              
863              
864             =item C<%T>
865              
866             The default themes for the transformer.
867              
868              
869             =item C<%t>
870              
871             The current themes for the transformer.
872              
873              
874             =item C<%V>
875              
876             The default maximum number of transformations per document of the transformer.
877              
878              
879             =item C<%v>
880              
881             The current maximum number of transformations per document of the transformer.
882              
883              
884             =back
885              
886              
887             =head1 AUTHOR
888              
889             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
890              
891              
892             =head1 COPYRIGHT
893              
894             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
895              
896             This program is free software; you can redistribute it and/or modify
897             it under the same terms as Perl itself. The full text of this license
898             can be found in the LICENSE file included with this module.
899              
900             =cut
901              
902             # Local Variables:
903             # mode: cperl
904             # cperl-indent-level: 4
905             # fill-column: 78
906             # indent-tabs-mode: nil
907             # c-indentation-style: bsd
908             # End:
909             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :