GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Code::Perl(3) User Contributed Perl Documentation Code::Perl(3)

Code::Perl - Produce Perl code from a tree

  use Code::Perl::Expr qw( :easy );

  my $c = derefh(scal('hash'), calls('getkey'));

  print $c->perl; # ($hash)->{getkey()}

Code::Perl allows you to build chunks of Perl code as a tree and then when you're finished building, the tree can output the Perl code. This is useful if you have built your own mini-language and you want to generate Perl from it. Rather than generating the Perl at parse time and having to worry about quoting, escaping, parenthese etc, you can just build a tree using Code::Perl and then dump out the correct Perl at the end.

All objects in Code::Perl conform to a basic interface. They all have a method "perl()" which when called returns a string of Perl code corresponding to the object. So for example

  my $s_i = Code::Perl::Expr::Scalar->new(Name => 'i');
  print $s_i->perl; # $i

  my $string = Code::Perl::Expr::String->new(Value => 'hello');
  print $string->perl; # "hello"

  my $list = Code::Perl::Expr::List(Value => [$s_i, $string]);
  print $list->perl; # $i, "hello"

  my $sub = Code::Perl::Expr::CallSub(SubName => "fn", Args => $list);
  print $sub->perl; # fn($i, "hello")

Expression types may also implement other methods but they vary from type to type, "perl()" is the only method that is mandatory.

Code::Perl is in development. There are no known bugs however it currently only has support for a limited range of operators, just enough to allow me to compile the TALES expression from Zope's TAL (http://www.zope.com/). Hopefully this will allow Petal (a Perl implementation of TAL) to produce faster code.

See Code::Perl::Expr for details of the available expression types.

Code::Perl currently has no knowledge of operator precedence, so to be safe it uses parentheses even when they are not needed. The code is correct but it will be a little longer and less readable. It should have no impact on the efficience of the code produced.

Written by Fergal Daly <fergal@esatclear.ie>.

Copyright 2003 by Fergal Daly <fergal@esatclear.ie>.

This program is free software and comes with no warranty. It is distributed under the LGPL license

See the file LGPL included in this distribution or http://www.fsf.org/licenses/licenses.html.

2003-06-17 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.