Acme-Constructor-Pythonic
view release on metacpan or search on metacpan
NAME
Acme::Constructor::Pythonic - import Python-style constructor functions
SYNOPSIS
use Acme::Constructor::Pythonic qw(
LWP::UserAgent
JSON
HTTP::Request
);
my $json = JSON();
my $ua = UserAgent();
my $req = Request( GET => 'http://www.example.com/foo.json' );
my $data = $json->decode( $ua->request($req)->content )
DESCRIPTION
In Python you import classes like this:
import BankAccount from banking
And you instantiate them with something looking like a function call:
acct = BankAccount(9.99)
This module allows Python-like object instantiation in Perl. The example
in the SYNOPSIS creates three functions `UserAgent`, `JSON` and <Request>
each of which just pass through their arguments to the real object
constructors.
Options
Each argument to the Acme::Constructor::Pythonic is a Perl module name and
may be followed by a hashref of options:
use Acme::Constructor::Pythonic
'A::Module',
'Another::Module' => \%some_options,
'Yes::Another::Module',
;
* class
The class to call the constructor on. This is normally the same as the
module name, and that's the default assumption, so there's no usually
much point in providing it.
* constructor
The method name for the constructor. The default is `new` which is
usually correct.
* alias
The name of the function you want created for you. The default is the
last component of the module name, which is often sensible.
* no_require
Acme::Constructor::Python will automatically load the module
specified. Not straight away; it waits until you actually perform an
instantiation. If you don't want Acme::Constructor::Python to load the
module, then set this option to true.
BUGS
Please report any bugs to
<http://rt.cpan.org/Dist/Display.html?Queue=Acme-Constructor-Pythonic>.
SEE ALSO
( run in 0.487 second using v1.01-cache-2.11-cpan-39bf76dae61 )