File Coverage

blib/lib/Perl/ToPerl6/Command.pm
Criterion Covered Total %
statement 90 290 31.0
branch 27 114 23.6
condition 24 53 45.2
subroutine 20 39 51.2
pod 1 1 100.0
total 162 497 32.6


line stmt bran cond sub pod time code
1             package Perl::ToPerl6::Command;
2              
3 3     3   6465 use 5.006001;
  3         10  
4 3     3   16 use strict;
  3         3  
  3         72  
5 3     3   13 use warnings;
  3         5  
  3         101  
6              
7 3     3   758 use English qw< -no_match_vars >;
  3         2487  
  3         19  
8 3     3   2559 use Readonly;
  3         7571  
  3         187  
9              
10 3     3   2831 use Getopt::Long qw< GetOptions >;
  3         33251  
  3         18  
11 3     3   622 use List::Util qw< first max >;
  3         5  
  3         284  
12 3     3   2035 use Pod::Usage qw< pod2usage >;
  3         1217178  
  3         318  
13              
14 3     3   1047 use Perl::ToPerl6::Exception::Parse ();
  3         8  
  3         92  
15 3         213 use Perl::ToPerl6::Utils qw<
16             :characters :severities transformer_short_name
17             $DEFAULT_VERBOSITY $DEFAULT_VERBOSITY_WITH_FILE_NAME
18 3     3   15 >;
  3         6  
19 3     3   1841 use Perl::ToPerl6::Utils::Constants qw< $_MODULE_VERSION_TERM_ANSICOLOR >;
  3         5  
  3         290  
20 3     3   852 use Perl::ToPerl6::Transformation qw<>;
  3         10  
  3         151  
21              
22             #-----------------------------------------------------------------------------
23              
24             our $VERSION = '0.03';
25              
26             #-----------------------------------------------------------------------------
27              
28 3     3   17 use Exporter 'import';
  3         6  
  3         10120  
29              
30             Readonly::Array our @EXPORT_OK => qw< run >;
31              
32             Readonly::Hash our %EXPORT_TAGS => (
33             all => [ @EXPORT_OK ],
34             );
35              
36             #-----------------------------------------------------------------------------
37              
38             Readonly::Scalar my $DEFAULT_VIOLATIONS_FOR_TOP => 20;
39              
40             Readonly::Scalar my $EXIT_SUCCESS => 0;
41             Readonly::Scalar my $EXIT_NO_FILES => 1;
42             Readonly::Scalar my $EXIT_HAD_VIOLATIONS => 2;
43             Readonly::Scalar my $EXIT_HAD_FILE_PROBLEMS => 3;
44              
45             #-----------------------------------------------------------------------------
46              
47             my @files = ();
48             my $mogrify = undef;
49             my $output = \*STDOUT;
50              
51             #-----------------------------------------------------------------------------
52              
53             sub _out {
54 0     0   0 my @lines = @_;
55 0         0 return print {$output} @lines;
  0         0  
56             }
57              
58             #-----------------------------------------------------------------------------
59              
60             sub run {
61 0     0 1 0 my %options = _get_options();
62 0         0 @files = _get_input(@ARGV);
63              
64 0         0 my ($transformations, $had_error_in_file) = _transform(\%options, @files);
65              
66 0 0       0 return $EXIT_HAD_FILE_PROBLEMS if $had_error_in_file;
67 0 0       0 return $EXIT_NO_FILES if not defined $transformations;
68 0 0       0 return $EXIT_HAD_VIOLATIONS if $transformations;
69              
70 0         0 return $EXIT_SUCCESS;
71             }
72              
73             #-----------------------------------------------------------------------------
74              
75             sub _get_options {
76              
77 52     52   35289 my %opts = _parse_command_line();
78 52         147 _dispatch_special_requests( %opts );
79 49         121 _validate_options( %opts );
80              
81             # Convert severity shortcut options. If multiple shortcuts
82             # are given, the lowest one wins. If an explicit --severity
83             # option has been given, then the shortcuts are ignored. The
84             # @SEVERITY_NAMES variable is exported by Perl::ToPerl6::Utils.
85 44   100 172   387 $opts{-severity} ||= first { exists $opts{"-$_"} } @SEVERITY_NAMES;
  172         930  
86 44   100 162   359 $opts{-severity} ||= first { exists $opts{"-$_"} } ($SEVERITY_LOWEST .. $SEVERITY_HIGHEST);
  162         227  
87              
88              
89             # If --top is specified, default the severity level to 1, unless an
90             # explicit severity is defined. This provides us flexibility to
91             # report top-offenders across just some or all of the severity levels.
92             # We also default the --top count to twenty if none is given
93 44 100       148 if ( exists $opts{-top} ) {
94 5   100     22 $opts{-severity} ||= 1;
95 5   66     19 $opts{-top} ||= $DEFAULT_VIOLATIONS_FOR_TOP;
96             }
97              
98             #Override profile, if --noprofile is specified
99 44 100       97 if ( exists $opts{-noprofile} ) {
100 1         3 $opts{-profile} = $EMPTY;
101             }
102              
103 44         262 return %opts;
104             }
105              
106             #-----------------------------------------------------------------------------
107              
108             sub _parse_command_line {
109 52     52   94 my %opts;
110 52         111 my @opt_specs = _get_option_specification();
111 52         239 Getopt::Long::Configure('no_ignore_case');
112 52 50       1762 GetOptions( \%opts, @opt_specs ) || pod2usage(); #Exits
113              
114             # I've adopted the convention of using key-value pairs for
115             # arguments to most functions. And to increase legibility,
116             # I have also adopted the familiar command-line practice
117             # of denoting argument names with a leading dash (-).
118 52         121160 my %dashed_opts = map { ( "-$_" => $opts{$_} ) } keys %opts;
  75         299  
119 52         327 return %dashed_opts;
120             }
121              
122             #-----------------------------------------------------------------------------
123              
124             sub _dispatch_special_requests {
125 52     52   93 my (%opts) = @_;
126 52 100       156 if ( $opts{-help} ) { pod2usage( -verbose => 0 ) } # Exits
  1         3  
127 51 100       278 if ( $opts{-options} ) { pod2usage( -verbose => 1 ) } # Exits
  1         4  
128 50 100       118 if ( $opts{-man} ) { pod2usage( -verbose => 2 ) } # Exits
  1         2  
129 49 50       118 if ( $opts{-version} ) { _display_version() } # Exits
  0         0  
130 49 50       105 if ( $opts{-list} ) { _render_all_transformer_listing() } # Exits
  0         0  
131 49 50       102 if ( $opts{'-list-enabled'} ) { _render_transformer_listing(%opts) } # Exits
  0         0  
132 49 50       95 if ( $opts{'-list-themes'} ) { _render_theme_listing() } # Exits
  0         0  
133 49 50       105 if ( $opts{'-profile-proto'} ) { _render_profile_prototype() } # Exits
  0         0  
134 49 50       119 if ( $opts{-doc} ) { _render_transformer_docs( %opts ) } # Exits
  0         0  
135 49         78 return 1;
136             }
137              
138             #-----------------------------------------------------------------------------
139              
140             sub _validate_options {
141 49     49   82 my (%opts) = @_;
142 49         61 my $msg = $EMPTY;
143              
144              
145 49 100 100     154 if ( $opts{-noprofile} && $opts{-profile} ) {
146 1         3 $msg .= qq{Warning: Cannot use -noprofile with -profile option.\n};
147             }
148              
149 49 100 100     140 if ( $opts{-verbose} && $opts{-verbose} !~ m{(?: \d+ | %[mfFlcCedrpPs] )}xms) {
150 1         4 $msg .= qq<Warning: --verbose arg "$opts{-verbose}" looks odd. >;
151 1         3 $msg .= qq<Perhaps you meant to say "--verbose 3 $opts{-verbose}."\n>;
152             }
153              
154 49 100 100     166 if ( exists $opts{-top} && $opts{-top} < 0 ) {
155 1         4 $msg .= qq<Warning: --top argument "$opts{-top}" is negative. >;
156 1         4 $msg .= qq<Perhaps you meant to say "$opts{-top} --top".\n>;
157             }
158              
159 49 100 100     189 if (
      66        
160             exists $opts{-severity}
161             && (
162             $opts{-severity} < $SEVERITY_LOWEST
163             || $opts{-severity} > $SEVERITY_HIGHEST
164             )
165             ) {
166 2         4 $msg .= qq<Warning: --severity arg "$opts{-severity}" out of range. >;
167 2         4 $msg .= qq<Severities range from "$SEVERITY_LOWEST" (lowest) to >;
168 2         4 $msg .= qq<"$SEVERITY_HIGHEST" (highest).\n>;
169             }
170              
171              
172 49 100       96 if ( $msg ) {
173 5         16 pod2usage( -exitstatus => 1, -message => $msg, -verbose => 0); #Exits
174             }
175              
176              
177 44         67 return 1;
178             }
179              
180             #-----------------------------------------------------------------------------
181              
182             sub _get_input {
183              
184 0     0   0 my @args = @_;
185              
186 0 0 0     0 if ( !@args || (@args == 1 && $args[0] eq q{-}) ) {
      0        
187              
188             # Reading code from STDIN. All the code is slurped into
189             # a string. PPI will barf if the string is just whitespace.
190 0         0 my $code_string = do { local $RS = undef; <STDIN> };
  0         0  
  0         0  
191              
192             # Notice if STDIN was closed (pipe error, etc)
193 0 0       0 if ( ! defined $code_string ) {
194 0         0 $code_string = $EMPTY;
195             }
196              
197 0 0       0 $code_string =~ m{ \S+ }xms || die qq{Nothing to transform.\n};
198 0         0 return \$code_string; #Convert to SCALAR ref for PPI
199             }
200             else {
201              
202             # Test to make sure all the specified files or directories
203             # actually exist. If any one of them is bogus, then die.
204 0 0   0   0 if ( my $nonexistent = first { ! -e } @args ) {
  0         0  
205 0         0 my $msg = qq{No such file or directory: '$nonexistent'};
206 0         0 pod2usage( -exitstatus => 1, -message => $msg, -verbose => 0);
207             }
208              
209             # Reading code from files or dirs. If argument is a file,
210             # then we process it as-is (even though it may not actually
211             # be Perl code). If argument is a directory, recursively
212             # search the directory for files that look like Perl code.
213 0 0       0 return map { (-d) ? Perl::ToPerl6::Utils::all_perl_files($_) : $_ } @args;
  0         0  
214             }
215             }
216              
217             #------------------------------------------------------------------------------
218              
219             sub _transform {
220              
221 0     0   0 my ( $opts_ref, @files_to_transform ) = @_;
222 0 0       0 @files_to_transform || die "No perl files were found.\n";
223              
224             # Perl::ToPerl6 has lots of dependencies, so loading is delayed
225             # until it is really needed. This hack reduces startup time for
226             # doing other things like getting the version number or dumping
227             # the man page. Arguably, those things are pretty rare, but hey,
228             # why not save a few seconds if you can.
229              
230 0         0 require Perl::ToPerl6;
231 0         0 $mogrify = Perl::ToPerl6->new( %{$opts_ref} );
  0         0  
232 0 0       0 $mogrify->transformers() || die "No transformers selected.\n";
233              
234 0         0 _set_up_pager($mogrify->config()->pager());
235              
236 0         0 my $number_of_transformations = undef;
237 0         0 my $had_error_in_file = 0;
238              
239 0         0 for my $file (@files_to_transform) {
240              
241             eval {
242 0         0 my @transformations = $mogrify->transform($file);
243 0         0 $number_of_transformations += scalar @transformations;
244              
245 0 0       0 if (not $opts_ref->{'-statistics-only'}) {
246 0         0 _render_report( $file, $opts_ref, @transformations )
247             }
248 0         0 1;
249             }
250 0 0       0 or do {
251 0 0       0 if ( my $exception = Perl::ToPerl6::Exception::Parse->caught() ) {
    0          
252 0         0 $had_error_in_file = 1;
253 0         0 warn qq<Problem while mogrifying "$file": $EVAL_ERROR\n>;
254             }
255             elsif ($EVAL_ERROR) {
256             # P::C::Exception::Fatal includes the stack trace in its
257             # stringification.
258 0         0 die qq<Fatal error while mogrifying "$file": $EVAL_ERROR\n>;
259             }
260             else {
261 0         0 die qq<Fatal error while mogrifying "$file". Unfortunately, >,
262             q<$@/$EVAL_ERROR >,
263             qq<is empty, so the reason can't be shown.\n>;
264             }
265             }
266             }
267              
268 0 0 0     0 if ( $opts_ref->{-statistics} or $opts_ref->{'-statistics-only'} ) {
269 0         0 my $stats = $mogrify->statistics();
270 0         0 _report_statistics( $opts_ref, $stats );
271             }
272              
273 0         0 return $number_of_transformations, $had_error_in_file;
274             }
275              
276             #------------------------------------------------------------------------------
277              
278             sub _render_report {
279 0     0   0 my ( $file, $opts_ref, @transformations ) = @_;
280              
281             # Only report the files, if asked.
282 0         0 my $number_of_transformations = scalar @transformations;
283 0 0 0     0 if ( $opts_ref->{'-files-with-transformations'} ||
284             $opts_ref->{'-files-without-transformations'} ) {
285             not ref $file
286 0 0 0     0 and $opts_ref->{$number_of_transformations ? '-files-with-transformations' :
    0          
287             '-files-without-transformations'}
288             and _out "$file\n";
289 0         0 return $number_of_transformations;
290             }
291              
292             # Only report the number of transformations, if asked.
293 0 0       0 if( $opts_ref->{-count} ){
294 0 0       0 ref $file || _out "$file: ";
295 0         0 _out "$number_of_transformations\n";
296 0         0 return $number_of_transformations;
297             }
298              
299             # Hail all-clear unless we should shut up.
300 0 0 0     0 if( !@transformations && !$opts_ref->{-quiet} ) {
301 0 0       0 ref $file || _out "$file ";
302 0         0 _out "source OK\n";
303 0         0 return 0;
304             }
305              
306             # Otherwise, format and print transformations
307 0         0 my $verbosity = $mogrify->config->verbose();
308             # $verbosity can be numeric or string, so use "eq" for comparison;
309 0 0 0     0 $verbosity =
310             ($verbosity eq $DEFAULT_VERBOSITY && @files > 1)
311             ? $DEFAULT_VERBOSITY_WITH_FILE_NAME
312             : $verbosity;
313 0         0 my $fmt = Perl::ToPerl6::Utils::verbosity_to_format( $verbosity );
314 0 0       0 if (not -f $file) { $fmt =~ s< \%[fF] ><STDIN>xms; } #HACK!
  0         0  
315 0         0 Perl::ToPerl6::Transformation::set_format( $fmt );
316              
317 0         0 my $color = $mogrify->config->color();
318 0 0       0 _out $color ? _colorize_by_severity(@transformations) : @transformations;
319              
320 0         0 return $number_of_transformations;
321             }
322              
323             #-----------------------------------------------------------------------------
324              
325             sub _set_up_pager {
326 0     0   0 my ($pager_command) = @_;
327 0 0       0 return if not $pager_command;
328 0 0       0 return if not _at_tty();
329              
330 0 0       0 open my $pager, q<|->, $pager_command
331             or die qq<Unable to pipe to pager "$pager_command": $ERRNO\n>;
332              
333 0         0 $output = $pager;
334              
335 0         0 return;
336             }
337              
338             #-----------------------------------------------------------------------------
339              
340             sub _report_statistics {
341 0     0   0 my ($opts_ref, $statistics) = @_;
342              
343 0 0 0     0 if (
      0        
344             not $opts_ref->{'-statistics-only'}
345             and (
346             $statistics->total_transformations()
347             or not $opts_ref->{-quiet} and $statistics->modules()
348             )
349             ) {
350 0         0 _out "\n"; # There's prior output that we want to separate from.
351             }
352              
353 0         0 my $files = _commaify($statistics->modules());
354 0         0 my $subroutines = _commaify($statistics->subs());
355 0         0 my $statements = _commaify($statistics->statements_other_than_subs());
356 0         0 my $lines = _commaify($statistics->lines());
357 0         0 my $width = max map { length } $files, $subroutines, $statements;
  0         0  
358              
359 0         0 _out sprintf "%*s %s.\n", $width, $files, 'files';
360 0         0 _out sprintf "%*s %s.\n", $width, $subroutines, 'subroutines/methods';
361 0         0 _out sprintf "%*s %s.\n", $width, $statements, 'statements';
362              
363 0         0 my $lines_of_blank = _commaify( $statistics->lines_of_blank() );
364 0         0 my $lines_of_comment = _commaify( $statistics->lines_of_comment() );
365 0         0 my $lines_of_data = _commaify( $statistics->lines_of_data() );
366 0         0 my $lines_of_perl = _commaify( $statistics->lines_of_perl() );
367 0         0 my $lines_of_pod = _commaify( $statistics->lines_of_pod() );
368              
369             $width =
370 0         0 max map { length }
  0         0  
371             $lines_of_blank, $lines_of_comment, $lines_of_data,
372             $lines_of_perl, $lines_of_pod;
373 0         0 _out sprintf "\n%s %s:\n", $lines, 'lines, consisting of';
374 0         0 _out sprintf " %*s %s.\n", $width, $lines_of_blank, 'blank lines';
375 0         0 _out sprintf " %*s %s.\n", $width, $lines_of_comment, 'comment lines';
376 0         0 _out sprintf " %*s %s.\n", $width, $lines_of_data, 'data lines';
377 0         0 _out sprintf " %*s %s.\n", $width, $lines_of_perl, 'lines of Perl code';
378 0         0 _out sprintf " %*s %s.\n", $width, $lines_of_pod, 'lines of POD';
379              
380 0         0 my $average_sub_mccabe = $statistics->average_sub_mccabe();
381 0 0       0 if (defined $average_sub_mccabe) {
382 0         0 _out
383             sprintf
384             "\nAverage McCabe score of subroutines was %.2f.\n",
385             $average_sub_mccabe;
386             }
387              
388 0         0 _out "\n";
389              
390 0         0 _out _commaify($statistics->total_transformations()), " transformations.\n";
391              
392 0         0 my $transformations_per_file = $statistics->transformations_per_file();
393 0 0       0 if (defined $transformations_per_file) {
394 0         0 _out
395             sprintf
396             "Transformations per file was %.3f.\n",
397             $transformations_per_file;
398             }
399 0         0 my $transformations_per_statement = $statistics->transformations_per_statement();
400 0 0       0 if (defined $transformations_per_statement) {
401 0         0 _out
402             sprintf
403             "Transformations per statement was %.3f.\n",
404             $transformations_per_statement;
405             }
406 0         0 my $transformations_per_line = $statistics->transformations_per_line_of_code();
407 0 0       0 if (defined $transformations_per_line) {
408 0         0 _out
409             sprintf
410             "Transformations per line of code was %.3f.\n",
411             $transformations_per_line;
412             }
413              
414 0 0       0 if ( $statistics->total_transformations() ) {
415 0         0 _out "\n";
416              
417 0         0 my %severity_transformations = %{ $statistics->transformations_by_severity() };
  0         0  
418 0         0 my @severities = reverse sort keys %severity_transformations;
419             $width =
420             max
421 0         0 map { length _commaify( $severity_transformations{$_} ) }
  0         0  
422             @severities;
423 0         0 foreach my $severity (@severities) {
424             _out
425             sprintf
426             "%*s severity %d transformations.\n",
427             $width,
428 0         0 _commaify( $severity_transformations{$severity} ),
429             $severity;
430             }
431              
432 0         0 _out "\n";
433              
434 0         0 my %transformer_transformations = %{ $statistics->transformations_by_transformer() };
  0         0  
435 0         0 my @transformers = sort keys %transformer_transformations;
436             $width =
437             max
438 0         0 map { length _commaify( $transformer_transformations{$_} ) }
  0         0  
439             @transformers;
440 0         0 foreach my $transformer (@transformers) {
441             _out
442             sprintf
443             "%*s transformations of %s.\n",
444             $width,
445 0         0 _commaify($transformer_transformations{$transformer}),
446             transformer_short_name($transformer);
447             }
448             }
449              
450 0         0 return;
451             }
452              
453             #-----------------------------------------------------------------------------
454              
455             # Only works for integers.
456             sub _commaify {
457 0     0   0 my ( $number ) = @_;
458              
459 0         0 while ($number =~ s/ \A ( [-+]? \d+ ) ( \d{3} ) /$1,$2/xms) {
460             # nothing
461             }
462              
463 0         0 return $number;
464             }
465              
466             #-----------------------------------------------------------------------------
467              
468             sub _get_option_specification {
469              
470 52     52   668 return qw<
471             5 4 3 2 1
472             Safari
473             version
474             brutal
475             count|C
476             cruel
477             doc=s
478             exclude=s@
479             force!
480             gentle
481             harsh
482             help|?|H
483             include=s@
484             list
485             list-enabled
486             list-themes
487             man
488             color|colour!
489             noprofile
490             only!
491             options
492             pager=s
493             profile|p=s
494             profile-proto
495             quiet
496             severity=i
497             single-transformer|s=s
498             stern
499             statistics!
500             statistics-only!
501             profile-strictness=s
502             theme=s
503             top:i
504             allow-unsafe
505             verbose=s
506             color-severity-highest|colour-severity-highest|color-severity-5|colour-severity-5=s
507             color-severity-high|colour-severity-high|color-severity-4|colour-severity-4=s
508             color-severity-medium|colour-severity-medium|color-severity-3|colour-severity-3=s
509             color-severity-low|colour-severity-low|color-severity-2|colour-severity-2=s
510             color-severity-lowest|colour-severity-lowest|color-severity-1|colour-severity-1=s
511             files-with-transformations|l
512             files-without-transformations|L
513             program-extensions=s@
514             >;
515             }
516              
517             #-----------------------------------------------------------------------------
518              
519             sub _colorize_by_severity {
520 0     0     my @transformations = @_;
521 0 0         return @transformations if _this_is_windows();
522 0 0         return @transformations if not eval {
523 0           require Term::ANSIColor;
524 0           Term::ANSIColor->VERSION( $_MODULE_VERSION_TERM_ANSICOLOR );
525 0           1;
526             };
527              
528 0           my $config = $mogrify->config();
529 0           my %color_of = (
530             $SEVERITY_HIGHEST => $config->color_severity_highest(),
531             $SEVERITY_HIGH => $config->color_severity_high(),
532             $SEVERITY_MEDIUM => $config->color_severity_medium(),
533             $SEVERITY_LOW => $config->color_severity_low(),
534             $SEVERITY_LOWEST => $config->color_severity_lowest(),
535             );
536              
537 0           return map { _colorize( "$_", $color_of{$_->severity()} ) } @transformations;
  0            
538              
539             }
540              
541             #-----------------------------------------------------------------------------
542              
543             sub _colorize {
544 0     0     my ($string, $color) = @_;
545 0 0         return $string if not defined $color;
546 0 0         return $string if $color eq $EMPTY;
547             # $terminator is a purely cosmetic change to make the color end at the end
548             # of the line rather than right before the next line. It is here because
549             # if you use background colors, some console windows display a little
550             # fragment of colored background before the next uncolored (or
551             # differently-colored) line.
552 0 0         my $terminator = chomp $string ? "\n" : $EMPTY;
553 0           return Term::ANSIColor::colored( $string, $color ) . $terminator;
554             }
555              
556             #-----------------------------------------------------------------------------
557              
558             sub _this_is_windows {
559 0 0   0     return 1 if $OSNAME =~ m/MSWin32/xms;
560 0           return 0;
561             }
562              
563             #-----------------------------------------------------------------------------
564              
565             sub _at_tty {
566 0     0     return -t STDOUT;
567             }
568              
569             #-----------------------------------------------------------------------------
570              
571             sub _render_all_transformer_listing {
572             # Force P-C parameters, to catch all Transformers on this site
573 0     0     my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST);
574 0           return _render_transformer_listing( %pc_params );
575             }
576              
577             #-----------------------------------------------------------------------------
578              
579             sub _render_transformer_listing {
580 0     0     my %pc_params = @_;
581              
582 0           require Perl::ToPerl6::TransformerListing;
583 0           require Perl::ToPerl6;
584              
585 0           my @transformers = Perl::ToPerl6->new( %pc_params )->transformers();
586 0           my $listing = Perl::ToPerl6::TransformerListing->new( -transformers => \@transformers );
587 0           _out $listing;
588              
589 0           exit $EXIT_SUCCESS;
590             }
591              
592             #-----------------------------------------------------------------------------
593              
594             sub _render_theme_listing {
595              
596 0     0     require Perl::ToPerl6::ThemeListing;
597 0           require Perl::ToPerl6;
598              
599 0           my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST);
600 0           my @transformers = Perl::ToPerl6->new( %pc_params )->transformers();
601 0           my $listing = Perl::ToPerl6::ThemeListing->new( -transformers => \@transformers );
602 0           _out $listing;
603              
604 0           exit $EXIT_SUCCESS;
605             }
606              
607             #-----------------------------------------------------------------------------
608              
609             sub _render_profile_prototype {
610              
611 0     0     require Perl::ToPerl6::ProfilePrototype;
612 0           require Perl::ToPerl6;
613              
614 0           my %pc_params = (-profile => $EMPTY, -severity => $SEVERITY_LOWEST);
615 0           my @transformers = Perl::ToPerl6->new( %pc_params )->transformers();
616 0           my $prototype = Perl::ToPerl6::ProfilePrototype->new( -transformers => \@transformers );
617 0           _out $prototype;
618              
619 0           exit $EXIT_SUCCESS;
620             }
621              
622             #-----------------------------------------------------------------------------
623              
624             sub _render_transformer_docs {
625              
626 0     0     my (%opts) = @_;
627 0           my $pattern = delete $opts{-doc};
628              
629 0           require Perl::ToPerl6;
630 0           $mogrify = Perl::ToPerl6->new(%opts);
631 0           _set_up_pager($mogrify->config()->pager());
632              
633 0           require Perl::ToPerl6::TransformerFactory;
634 0           my @site_transformers = Perl::ToPerl6::TransformerFactory->site_transformer_names();
635 0           my @matching_transformers = grep { /$pattern/ixms } @site_transformers;
  0            
636              
637             # "-T" means don't send to pager
638 0           my @perldoc_output = map {`perldoc -T $_`} @matching_transformers;
  0            
639 0           _out @perldoc_output;
640              
641 0           exit $EXIT_SUCCESS;
642             }
643              
644             #-----------------------------------------------------------------------------
645              
646             sub _display_version {
647 0     0     _out "$VERSION\n";
648 0           exit $EXIT_SUCCESS;
649             }
650              
651             #-----------------------------------------------------------------------------
652             1;
653              
654             __END__
655              
656             #-----------------------------------------------------------------------------
657              
658             =pod
659              
660             =for stopwords
661             Twitter
662              
663             =head1 NAME
664              
665             Perl::ToPerl6::Command - Guts of L<perlmogrify|perlmogrify>.
666              
667              
668             =head1 SYNOPSIS
669              
670             use Perl::ToPerl6::Command qw< run >;
671              
672             local @ARGV = qw< --statistics-only lib bin >;
673             run();
674              
675              
676             =head1 DESCRIPTION
677              
678             This is the implementation of the L<perlmogrify|perlmogrify> command. You can use
679             this to run the command without going through a command interpreter.
680              
681              
682             =head1 INTERFACE SUPPORT
683              
684             This is considered to be a public class. However, its interface is
685             experimental, and will likely change.
686              
687              
688             =head1 IMPORTABLE SUBROUTINES
689              
690             =over
691              
692             =item C<run()>
693              
694             Does the equivalent of the L<perlmogrify|perlmogrify> command. Unfortunately, at
695             present, this doesn't take any parameters but uses C<@ARGV> to get its
696             input instead. Count on this changing; don't count on the current
697             interface.
698              
699              
700             =back
701              
702              
703             =head1 TO DO
704              
705             Make C<run()> take parameters. The equivalent of C<@ARGV> should be
706             passed as a reference.
707              
708             Turn this into an object.
709              
710              
711             =head1 AUTHOR
712              
713             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
714              
715              
716             =head1 COPYRIGHT
717              
718             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
719              
720             This program is free software; you can redistribute it and/or modify
721             it under the same terms as Perl itself. The full text of this license
722             can be found in the LICENSE file included with this module.
723              
724             =cut
725              
726             ##############################################################################
727             # Local Variables:
728             # mode: cperl
729             # cperl-indent-level: 4
730             # fill-column: 78
731             # indent-tabs-mode: nil
732             # c-indentation-style: bsd
733             # End:
734             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :