#!/usr/bin/perl
# Copyright (C) 2008, The Perl Foundation.
# $Id$

use strict;
use warnings;

my @files = @ARGV;

print <<"END_SETTING";
# This file automatically generated by $0.
no Main;

END_SETTING

foreach my $file (@files) {
    print "# From $file\n\n";
    open(my $fh, "< $file") or die $!;
    print join('', <$fh>);
    close $fh;
}

my @classes = ('Any');
foreach my $file (@files) {
    next unless $file =~ /setting((?:[\/\\]\w+)+)\.pm$/;
    my $full_modname = substr($1, 1);
    push @classes, $full_modname;
}

print <<"END_SETTING";
# Need to use all built-in classes, to import their exports.
sub SETTING_INIT() {
END_SETTING
s/\\/\//g for @classes;
print join('', map {
        my $colon_form = $_;
        $colon_form =~ s/[\/\\]/::/g;
        "  Perl6::Compiler.import('$colon_form', ':DEFAULT', ':MANDATORY');\n"
    } @classes);
print "}\n";

# Why yes, "OMFG" is a correct response to this hack. We need to make sure
# that we set up %*INC properly for the pre-compiled case, and can't use
# BEGIN blocks to preserve those changes for now.
#print <<"END_SETTING";
#Q:PIR {
#    .return (1)
#.end
#.sub '' :load :init
#};
#END_SETTING
#print join('', map { "\%*INC<$_> = 1;\n" } @classes);

#!/usr/bin/perl
# Copyright (C) 2008, The Perl Foundation.
# $Id$

use strict;
use warnings;

my @files = @ARGV;

print <<"END_SETTING";
# This file automatically generated by $0.
no Main;

END_SETTING

foreach my $file (@files) {
    print "# From $file\n\n";
    open(my $fh, "< $file") or die $!;
    print join('', <$fh>);
    close $fh;
}

my @classes = ('Any');
foreach my $file (@files) {
    next unless $file =~ /setting((?:[\/\\]\w+)+)\.pm$/;
    my $full_modname = substr($1, 1);
    push @classes, $full_modname;
}

print <<"END_SETTING";
# Need to import all built-in classes and set \%*INC for each.
sub SETTING_INIT() {
END_SETTING
s/\\/\//g for @classes;
print join('', map {
        my $colon_form = $_;
        $colon_form =~ s/[\/\\]/::/g;
        "  \%*INC<$_> = 1;\n  Perl6::Compiler.import('$colon_form', ':DEFAULT', ':MANDATORY');\n"
    } @classes);
print "}\n";


Add back %*INC settings, clean up code generation slightly.
Add back %*INC settings, clean up code generation slightly.
