Skip to main content

A Python wrapper for Perl subroutines

Reason this release was yanked:

buggy

Project description

perl-subroutine-wrapper

A Python wrapper for Perl subroutines.

This module makes it easy to call your Perl subroutines from Python. It is perfect for recycling old Perl code that you are not going to translate to Python.

It makes it possible to comunicate objects between the two languages through JSON object representations.

Valid Python objects passed as parameters are: dict, list, str, int, float, True, False, None.

Valid Perl objects returned are: SCALAR, ARRAY, HASH.

Installation

You can install this module from Pypi:

pip install perlsub

Requirements

In order to use this python module you will need to install jinja2, which will help us with generate the Perl intermediary wrapper dinamically when calling subroutines:

pip install jinja2

You also need Perl installed in your computer. You can check if it is installed and the version with the command:

perl -v

Example of usage

example.py and example.pm show us how to use the module. In example.pm we have a Perl subroutine such as join that we want to use in our Python script.

sub join { 
     my ($list1, $list2)=@_; 
     my @list3; 
     push @list3, @$list1; 
     push @list3, @$list2; 
     print "Joined :)"; 
     return @list3;
}

To wrap this subroutine and use it in Python we have to import the module, create a new Module instance passing the path of the Perl module, and call the call function passing the name of the subroutine, the parameters and the expected Perl object returned like I did in example.py. parameters and returned_type can be None.

from perlsub import Module


example = Module('example.pm')

join = example.call(
  subroutine='join', 
  parameters=[[2, 3], [1, 1]], 
  return_type='array'
)
print(join)
Output:

PerlCallResult(returned=[2, 3, 1, 1], stdout='Joined :)', error=None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perlsub-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

perlsub-0.0.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file perlsub-0.0.2.tar.gz.

File metadata

  • Download URL: perlsub-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for perlsub-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4022a375aa9c868c51253ea2bacc70e3cf0831ded349cd6239b58ee10cc007f1
MD5 6fa6ed958142998ced3a2e87fd288773
BLAKE2b-256 c5bb1dd58764351cfd7a9381e24d3ab958d35ebc06d2850dced7c53792afa46d

See more details on using hashes here.

File details

Details for the file perlsub-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: perlsub-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for perlsub-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74e411605f9d68c61e0e6918ea2249ae84bb1c1a6e4be4f9967ddc2e3f353aa4
MD5 1703f971a5beae5eb76a82e372f1e1fc
BLAKE2b-256 084a8cec8f39c0e285c4b0d4da61be42d2dd55b80c308c3fe8f6a719387122ad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page