README
1NAME
2 Code::Perl - Produce Perl code from a tree
3
4SYNOPSIS
5 use Code::Perl::Expr qw( :easy );
6
7 my $c = derefh(scal('hash'), calls('getkey'));
8
9 print $c->perl; # ($hash)->{getkey()}
10
11DESCRIPTION
12 Code::Perl allows you to build chunks of Perl code as a tree and then when
13 you're finished building, the tree can output the Perl code. This is useful
14 if you have built your own mini-language and you want to generate Perl from
15 it. Rather than generating the Perl at parse time and having to worry about
16 quoting, escaping, parenthese etc, you can just build a tree using
17 Code::Perl and then dump out the correct Perl at the end.
18
19INTERFACE
20 All objects in Code::Perl conform to a basic interface. They all have a
21 method "perl()" which when called returns a string of Perl code
22 corresponding to the object. So for example
23
24 my $s_i = Code::Perl::Expr::Scalar->new(Name => 'i');
25 print $s_i->perl; # $i
26
27 my $string = Code::Perl::Expr::String->new(Value => 'hello');
28 print $string->perl; # "hello"
29
30 my $list = Code::Perl::Expr::List(Value => [$s_i, $string]);
31 print $list->perl; # $i, "hello"
32
33 my $sub = Code::Perl::Expr::CallSub(SubName => "fn", Args => $list);
34 print $sub->perl; # fn($i, "hello")
35
36 Expression types may also implement other methods but they vary from type to
37 type, "perl()" is the only method that is mandatory.
38
39STATUS
40 Code::Perl is in development. There are no known bugs however it currently
41 only has support for a limited range of operators, just enough to allow me
42 to compile the TALES expression from Zope's TAL (http://www.zope.com/).
43 Hopefully this will allow Petal (a Perl implementation of TAL) to produce
44 faster code.
45
46USAGE
47 See Code::Perl::Expr for details of the available expression types.
48
49PROBLEMS
50 Code::Perl currently has no knowledge of operator precedence, so to be safe
51 it uses parentheses even when they are not needed. The code is correct but
52 it will be a little longer and less readable. It should have no impact on
53 the efficience of the code produced.
54
55AUTHOR
56 Written by Fergal Daly <fergal@esatclear.ie>.
57
58COPYRIGHT
59 Copyright 2003 by Fergal Daly <fergal@esatclear.ie>.
60
61 This program is free software and comes with no warranty. It is distributed
62 under the LGPL license
63
64 See the file LGPL included in this distribution or
65 http://www.fsf.org/licenses/licenses.html.
66
67