Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

created by proto's create-new-project

  • Loading branch information...
commit 471e136d5cd17d2e74875ca9fd0f95a6aeb2f2b9 0 parents
Jonathan Scott Duff authored May 26, 2009
2  Configure.pl
... ...
@@ -0,0 +1,2 @@
  1
+# Configure.pl - installer - see documentation in lib/Configure.pm
  2
+use v6; BEGIN { @*INC.unshift( 'lib' ); }; use Configure;
36  Makefile.in
... ...
@@ -0,0 +1,36 @@
  1
+PERL6=<PERL6>
  2
+PERL6LIB=<PERL6LIB>
  3
+RAKUDO_DIR=<RAKUDO_DIR>
  4
+
  5
+SOURCES=lib/Example/Hello.pm
  6
+
  7
+
  8
+PIRS=$(SOURCES:.pm=.pir)
  9
+
  10
+all: $(PIRS) lib/Test.pir
  11
+
  12
+%.pir: %.pm
  13
+	$(PERL6) --target=pir --output=$@ $<
  14
+
  15
+lib/Test.pir: $(RAKUDO_DIR)/Test.pm $(PERL6)
  16
+	$(PERL6) --target=pir --output=lib/Test.pir $(RAKUDO_DIR)/Test.pm
  17
+
  18
+clean:
  19
+	rm -f $(PIRS)
  20
+
  21
+realclean: clean
  22
+	rm Makefile
  23
+
  24
+test: all
  25
+	PERL6LIB=$(PERL6LIB) prove -e '$(PERL6)' -r --nocolor t/
  26
+
  27
+help:
  28
+	@echo ''
  29
+	@echo 'You can make the following targets:'
  30
+	@echo ''
  31
+	@echo 'all       - default, precompile .pm to .pir for speed'
  32
+	@echo 'clean     - removes .pir and backup~ files'
  33
+	@echo 'realclean - clean and also remove Makefile'
  34
+	@echo 'test      - verify that the code works as specified'
  35
+	@echo 'help      - this text.'
  36
+	@echo ''
1  deps.proto
... ...
@@ -0,0 +1 @@
  1
+# project dependencies
142  lib/Configure.pm
... ...
@@ -0,0 +1,142 @@
  1
+# Configure.pm
  2
+
  3
+.say for
  4
+    '',
  5
+    'Configure.pm is preparing to make your Makefile.',
  6
+    '';
  7
+
  8
+# Determine how this Configure.p6 was invoked, to write the same paths
  9
+# and executables into the Makefile variables. The variables are:
  10
+# PERL6       how to execute a Perl 6 script
  11
+# PERL6LIB    initial value of @*INC, where 'use <module>;' searches
  12
+# PERL6BIN    directory where executables such as 'prove' reside
  13
+# RAKUDO_DIR  (deprecated) currently the location of Rakudo's Test.pm
  14
+
  15
+my $parrot_dir = %*VM<config><build_dir>;
  16
+my $rakudo_dir;
  17
+my $perl6;
  18
+
  19
+regex parrot_in_rakudo { ( .* '/rakudo' ) '/parrot' }
  20
+
  21
+# There are two possible relationships between the parrot and rakudo
  22
+# directories: rakudo/parrot or parrot/languages/rakudo
  23
+if $parrot_dir ~~ / <parrot_in_rakudo> / {
  24
+    # first case, rakudo/parrot for example if installed using new
  25
+    # 'git clone ...rakudo.git' then 'perl Configure.pl --gen-parrot'
  26
+    $rakudo_dir = $parrot_dir.subst( / '/parrot' $ /, ''); #'
  27
+}
  28
+elsif "$parrot_dir/languages/rakudo" ~~ :d {
  29
+    # second case, parrot/languages/rakudo if installed the old way
  30
+    $rakudo_dir = "$parrot_dir/languages/rakudo";
  31
+}
  32
+else { # anything else 
  33
+    .say for
  34
+        "Found a PARROT_DIR to be $parrot_dir",
  35
+        'but there is no Rakudo nearby. Please contact the proto people.',
  36
+        '';
  37
+    exit(1);
  38
+}
  39
+if "$rakudo_dir/perl6" ~~ :f or "$rakudo_dir/perl6.exe" ~~ :f {
  40
+    $perl6 = "$rakudo_dir/perl6";  # the fake executable from pbc_to_exe
  41
+}
  42
+else {
  43
+    $perl6 = "$parrot_dir/parrot $rakudo_dir/perl6.pbc";
  44
+}
  45
+
  46
+say "PERL6       $perl6";
  47
+my $perl6lib = %*ENV<PERL6LIB>.index(%*ENV<PWD> ~ '/lib').defined
  48
+               ?? %*ENV<PERL6LIB>
  49
+               !! %*ENV<PWD> ~ '/lib';
  50
+say "PERL6LIB    $perl6lib";
  51
+# The perl6-examples/bin directory is a sibling of PERL6LIB
  52
+my $perl6bin = $perl6lib.subst( '/lib', '/bin' );
  53
+say "PERL6BIN    $perl6bin";
  54
+say "RAKUDO_DIR  $rakudo_dir";
  55
+
  56
+# Read Makefile.in, edit, write Makefile
  57
+my $maketext = slurp( 'Makefile.in' );
  58
+$maketext .= subst( .key, .value ) for
  59
+    'Makefile.in'       => 'Makefile',
  60
+    'To be read'        => 'Written',
  61
+    'replaces <TOKENS>' => 'defined these',
  62
+# Maintainer note: keep the following in sync with pod#VARIABLES below
  63
+    '<PERL6>'           => $perl6,
  64
+    '<PERL6LIB>'        => $perl6lib,
  65
+    '<PERL6BIN>'        => $perl6bin,
  66
+    '<RAKUDO_DIR>'      => $rakudo_dir;
  67
+squirt( 'Makefile', $maketext );
  68
+
  69
+# Job done.
  70
+.say for
  71
+    '',
  72
+    q[Makefile is ready, and you can run 'make'.];
  73
+
  74
+# The opposite of slurp
  75
+sub squirt( Str $filename, Str $text ) {
  76
+    my $handle = open( $filename, :w )
  77
+        or die $!;
  78
+    $handle.print: $text;
  79
+    $handle.close;
  80
+}
  81
+
  82
+# This Configure.pm can work with the following ways of starting up:
  83
+# 1. The explicit way Parrot runs any Parrot Byte Code:
  84
+#    /my/parrot/parrot /my/rakudo/perl6.pbc Configure.p6
  85
+# 2. The Rakudo "Fake Executable" made by pbc_to_exe:
  86
+#    /my/rakudo/perl6 Configure.p6
  87
+# The rest are variations of 1. and 2. to sugar the command line:
  88
+# 3. A shell script perl6 for 1: '/my/parrot/parrot /my/rakudo/perl6.pbc $*':
  89
+#    /my/perl6 Configure.p6    # or 'perl6 Configure.p6' with search path
  90
+# 4. A shell alias for 1: perl6='/my/parrot/parrot /my/rakudo/perl6.pbc':
  91
+#    perl6 Configure.p6
  92
+# 5. A symbolic link for 2: 'sudo ln -s /my/rakudo/perl6 /bin':
  93
+#    perl6 Configure.p6
  94
+
  95
+# Do you know of another way to execute Perl 6 scripts? Please tell the
  96
+# maintainers.
  97
+
  98
+=begin pod
  99
+
  100
+=head1 NAME
  101
+Makefile.pm - common code for Makefile builder and runner
  102
+
  103
+=head1 SYNOPSIS
  104
+
  105
+ perl6 Configure.p6
  106
+
  107
+Where F<Configure.p6> generally has only these lines:
  108
+
  109
+ # Configure.p6 - installer - see documentation in ../Configure.pm
  110
+ use v6; BEGIN { @*INC.push( '../..' ); }; use Configure; # proto dir
  111
+
  112
+=head1 DESCRIPTION
  113
+A Perl module often needs a Makefile to specify how to build, test and
  114
+install it. A Makefile must make sense to the Unix C<make> utility.
  115
+Makefiles must often be adjusted slightly to alter the context in which
  116
+they will work. There are various tools to "make Makefiles" and this
  117
+F<Configure.p6> and F<Configure.pm> combination run purely in Perl 6.
  118
+
  119
+Configure.p6 resides in the module top level directory. For covenience,
  120
+Configure.p6 usually contains only the lines shown in L<doc:#SYNOPSIS>
  121
+above, namely a comment and one line of code to pass execution to
  122
+F<Configure.pm>. Any custom actions to prepare the module can be called
  123
+by the default target in Makefile.in.
  124
+
  125
+Configure.pm reads F<Makefile.in> from the module top level directory,
  126
+replaces certain variables marked like <THIS>, and writes the updated
  127
+text to Makefile in the same directory. Finally it runs the standard
  128
+'make' utility, which builds the first target defined in Makefile.
  129
+
  130
+=head1 VARIABLES
  131
+C<Configure.p6> will cause the following tokens to be substituted when
  132
+creating the new F<Makefile>:
  133
+
  134
+ <PERL6>        pathname of Perl 6 (fake)executable
  135
+ <PERL6LIB>     lib/ directory of the installed project
  136
+ <PERL6BIN>     bin/ directory of the installed project
  137
+ <RAKUDO_DIR>   whence Rakudo's Test.pm can be compiled
  138
+
  139
+=head1 AUTHOR
  140
+Martin Berends (mberends on CPAN github #perl6 and @autoexec.demon.nl).
  141
+
  142
+=end pod
11  lib/Example/Hello.pm
... ...
@@ -0,0 +1,11 @@
  1
+class Example::Hello
  2
+{
  3
+    method greet { return "hello" }
  4
+    method place { return "world" }
  5
+}
  6
+=begin pod
  7
+=head1 NAME
  8
+Example::Hello - canonical "hello, world!" example for proto
  9
+=head1 AUTHOR
  10
+perlpilot (perlpilot at github and @example.com)
  11
+=end pod
7  t/01-simple.t
... ...
@@ -0,0 +1,7 @@
  1
+use Example::Hello;
  2
+use Test;
  3
+plan 3;
  4
+my Example::Hello $greeter .= new;
  5
+isa_ok( $greeter, 'Example::Hello', 'create object' );
  6
+is( $greeter.greet, 'hello', 'greet' );
  7
+is( $greeter.place, 'world', 'place' );

0 notes on commit 471e136

Please sign in to comment.
Something went wrong with that request. Please try again.