The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Acme::Syntax::Python - Python like Syntax for Perl.

SYNOPSIS

  use Acme::Syntax::Python;
  from Data::Dump import 'dump';

  def print_dump:
      print dump "Hello";

  print_dump;

DESCRIPTION

Translates a Python like syntax into executable Perl code. Right now blocks are defined by 4 spaces. I plan on extending this to tabs as well soon.

MODULES

Include modules into your file is much like the Python way using import.

  import Data::Dump;

this would include the Data::Dump module and whatever it exported by default.

If you need to exlicity name exports you can using "from"

  from Data::Dump import 'dump';

With perl you can also define params for use, with those you would just use import as a syntatic change of use.

  import Test::More tests => 4;

FUNCTIONS

You can declare Functions just like you would in Python.

ex: Function with no Paramaters:

  def hello_world:
      print "Hello World";

You can also declare functions with Paramaters:

  def hello($say):
      print "Hello $say";

  hello("World");

It will automatically define the variable for you and assign it from the paramater list.

LAMBDA

Lambas are also supported as a named definition:

  my $sub = lambda: 5 * 2;

  print $sub->();

Would print 10.

You can declare params for lambdas just like functions:

  my $sub = lambda ($x): $x * 2;

  print $sub->(5);

Would print 10 as well.

IF/ELIF/ELSE

If/Else is the same as python as well, just you cannot omit the ()'s around the condition statements. The Conditionals are still the same Perl conditionals.

  if ($1 eq "hello"):
      print "I received Hello!";
  elif ($2 eq "world"):
      print "I received World!";
  else:
      print "No mathces for me";

Conditionals can also span multiple lines like normal:

  if($bar == 1 &&
     $foo == 2):
      print "Truth";

CLASSES

Class definitions are supported as well, though translated in Perl they're just a Namespace declaration.

  class Foo:
      def bar:
          print "baz";

  Foo::baz();

You can also create Class Objects, using __init__ as the "sub new" constructor. If declaring your paramaters for a Method in a Object class you need to declare $self first.

  class Foo:
      def __init__($bar):
          $self->{bar} = $bar;

      def bar($self):
          print $self->{bar};

  $baz = Foo->new("bar");
  print $baz->bar();

Classes can also handle inheritance of other modules:

  use Acme::Syntax::Python; 
  class Foo inherits File::Find:
      def bar:
          print "baz";

  import Foo;
  Foo::find(\&wanted, "./");

If you wanted to write an entire object class with this then you would put the class in it's own .pm file like normal and include it in the Perl file like normal.

VERSION

This documentation describes version 0.02.

AUTHOR

 Madison Koenig <pedlar AT cpan DOT org>

COPYRIGHT

Copyright (c) 2013 Madison Koenig All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.