1 package Module::Install::DSL;
4 use vars qw{$VERSION $ISCORE};
8 *inc::Module::Install::DSL::VERSION = *VERSION;
9 @inc::Module::Install::DSL::ISA = __PACKAGE__;
13 # Read in the rest of the Makefile.PL
14 open 0 or die "Couldn't open $0: $!";
21 # Change inc::Module::Install::DSL to the regular one.
22 # Remove anything before the use inc::... line.
23 $dsl =~ s/.*?^\s*use\s+(?:inc::)?Module::Install::DSL(\b[^;]*);\s*\n//sm;
25 # Load inc::Module::Install as we would in a regular Makefile.Pl
28 require inc::Module::Install;
29 inc::Module::Install->import;
32 # Add the ::DSL plugin to the list of packages in /inc
33 my $admin = $Module::Install::MAIN->{admin};
35 my $from = $INC{"$admin->{path}/DSL.pm"};
36 my $to = "$admin->{base}/$admin->{prefix}/$admin->{path}/DSL.pm";
37 $admin->copy( $from => $to );
40 # Convert the basic syntax to code
41 my $code = "package main;\n\n"
43 . "\n\nWriteAll();\n";
47 print STDERR "Failed to execute the generated code" if $@;
55 # Split into lines and strip blanks
56 my @lines = grep { /\S/ } split /[\012\015]+/, $dsl;
58 # Each line represents one command
60 foreach my $line ( @lines ) {
61 # Split the lines into tokens
62 my @tokens = split /\s+/, $line;
64 # The first word is the command
65 my $command = shift @tokens;
69 my $token = shift @tokens;
70 if ( $token eq 'if' or $token eq 'unless' ) {
71 # This is the beginning of a suffix
73 push @suffix, @tokens;
77 $token =~ s/([\\\'])/\\$1/g;
78 push @params, "'$token'";
82 # Merge to create the final line of code
83 @tokens = ( $command, @params ? join( ', ', @params ) : (), @suffix );
84 push @code, join( ' ', @tokens ) . ";\n";
87 # Join into the complete code block
88 return join( '', @code );