File: compile.pm

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (56 lines) | stat: -rw-r--r-- 973 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Catmandu::Cmd::compile;

use Catmandu::Sane;

our $VERSION = '1.2024';

use parent 'Catmandu::Cmd';
use Catmandu;
use Data::Dumper;
use namespace::clean;

sub command_opt_spec {
    (
        ["var=s%",        ""],
        ["preprocess|pp", ""],
        ["fix|fix=s@",    "", {hidden => 1}],
    );
}

sub command {
    my ($self, $opts, $args) = @_;

    unless (@$args == 1) {
        say STDERR "usage: $0 compile <FILE>|<FIX> [<FILE>|<FIX> [...]]\n";
        exit 1;
    }

    $opts->{fix} = $args;

    my $fixer    = $self->_build_fixer($opts);
    my $fixes    = $fixer->emit;
    my $captures = Dumper($fixer->_captures);

    $captures =~ s/^\$VAR1/\$_[1]/;

    print $captures;
    print $fixes;
}

1;

__END__

=pod

=head1 NAME

Catmandu::Cmd::compile - compile a Fix into Perl (for debugging)

=head1 EXAMPLES

  catmandu compile <FILE>|<FIX> [<FILE>|<FIX> [...]]

  catmandu compile 'add_field(foo,bar.$append)' | perltidy -utf8 -npro -st -se

=cut