Acme-Chef
view release on metacpan or search on metacpan
script/compilechef view on Meta::CPAN
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Pod::Usage;
use lib 'lib';
use Acme::Chef;
use vars qw/$VERSION/;
$VERSION = '0.05';
@ARGV or pod2usage(
-msg => "You need to specify a .chef file to compile.",
-verbose => 2, # Manual
);
my $program_file = shift @ARGV;
my $target_file = shift @ARGV;
-f $program_file or pod2usage(
-msg => "You specified an invalid source filename.",
-verbose => 0, # Only synopsis
);
not defined $target_file and pod2usage(
-msg => "You specified an invalid target filename.",
-verbose => 0, # Only synopsis
);
open my $fh, '<', $program_file or pod2usage(
-msg => "You specified an invalid filename.",
-verbose => 0, # Only synopsis
);
local $/ = undef;
my $code = <$fh>;
close $fh;
my $compiled = Acme::Chef->compile($code);
my $module_code;
foreach my $module (
qw(
Acme::Chef::Ingredient Acme::Chef::Container
Acme::Chef Acme::Chef::Recipe
)
) {
my $module_file = join '/', (split /::/, $module);
my $full_path;
foreach my $dir (@INC) {
my $directory = $dir;
$directory =~ s/\/$//;
my $file = "$directory/$module_file.pm";
if (-f $file) {
$full_path = $file;
last;
}
}
die "Could not find $module in \@INC."
if not defined $full_path;
( run in 0.840 second using v1.01-cache-2.11-cpan-39bf76dae61 )