Krzysiek has asked for the wisdom of the Perl Monks concerning the following question:

Hi, monks.

I'm trying to rewrite rake, "build language" so it would fit within perl. If you don't know what is rake here you find all the info:

Rake project main page:
http://rake.rubyforge.org/

Rake syntax:
http://rake.rubyforge.org/files/doc/rakefile_rdoc.html

Rake tutorial:
http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial

In general it's a embedded domain specific language doing same things as the unix make util but it is using only ruby language

The source code of what I've done till this moment is available at
http://manta.univ.gda.pl/~ksuchoms/pake-final.tar.gz
You will find there:

pake - main app, definition of method available in Pakefile try running: ./pake -T
./pake test3
./pake program

I would like to know if I there are any other perl syntax rules which I could use in the Pakefile (Pakefile is like Makefile). Right now creating dependencies looks like this:

desc "task simply prints test";
task {
     print "test\n";
} "test";

task {
     print "test1\n";
     use Pod::Html;
} "test1" => "test";

desc "another boring description";
task {
     print "test2\n";
} "test2"=> "test";

task{
     print "test3\n";
} "test3" => "test2", "test1" ;

task method registers new task for example with the name test3 which depends on test2 and test1.

Secondly I would like to know how exactly the sort routine works. Because I don't understand how the $a $b variables are passed to the anonymous subroutine. I would like to create $task variable within the anonymous subroutine I'm passing to the task method.

I would like to know if you have some other idea how to create pure perl make tool.

Thanks, Krzysiek.

Replies are listed 'Best First'.
Re: Perl - make tool
by ysth (Canon) on Aug 03, 2008 at 19:27 UTC
    Secondly I would like to know how exactly the sort routine works. Because I don't understand how the $a $b variables are passed to the anonymous subroutine. I would like to create $task variable within the anonymous subroutine I'm passing to the task method.
    In retrospect, sort's use of $a and $b was a mistake. Note that code like sort foo 1..10; usually aliases $a and $b in the current package, but foo may be declared in some other package, and never see the sort-provided values. So sort was modified to pass the two values to compare as actual parameters, if and only if the subroutine specified has a $$ prototype.

    For your case, just pass the task as a parameter to the anonymous sub.

Re: Perl - make tool
by InfiniteSilence (Curate) on Aug 03, 2008 at 18:08 UTC
    I agree with jethro, this is a bit of an open-ended question. Suggestions:
    • Move this source to a Subversion or CVS repository somewhere if you can. That way one doesn't have to expand all the files to see any one part.
    • From an online tutorial I see the Rails version can handle namespaces, so perhaps you want to add some kind of package capability. I didn't see anything like that in the included Pakefile.
    • A tutorial in POD format somewhere in the kit would help.
    This is an interesting project. I would like to see how it progresses in the future. If you could give it an overall version number that would help as well. Rename your archive from pake-final.tar.gz to pake-version-0.2 or something so we know what we are unpacking.

    Celebrate Intellectual Diversity

Re: Perl - make tool
by jethro (Monsignor) on Aug 03, 2008 at 17:58 UTC
    Shouldn't the question about syntax rules be more like: "I want to spexify feature x. How can I specify that in perl syntax" ? Or is there something you don't like about your syntax now?

    aliasing of $a and $b in sort is (to my knowledge) magical. That means its a built-in of the interpreter not available to us mere mortals (at least it was, maybe perl version 5.8 or 5.10 added access to it and I forgot)

    Ideas? You might add a default rule (i.e. the syntax to declare a rule as default)? You also might add a mechanism to enable implicit rules (the knowledge how to create a .o file from a .c file...).

Re: Perl - make tool
by eyepopslikeamosquito (Archbishop) on Aug 03, 2008 at 21:48 UTC

    A couple of related PM nodes I remember:

    PerlBuildSystem, on the CPAN, is under active development and worth a look.

    Internal DSLs like rake suffer from being limited to valid syntax of the host language only; that is, you can't invent new syntax to better express your domain. In theory, Perl 6, due to its macro capability, should prove a superior language for implementing internal DSLs.

Re: Perl - make tool
by Burak (Chaplain) on Aug 03, 2008 at 18:09 UTC