Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

+ -

  Ctypes for Perl: Intro and API spec on 2010.05.23 6:50

Posted by brian_d_foy on 2010.05.23 6:50
User Journal
Hello, good evening and welcome.

For the next few months I will be using this blog to help document and publicise my "Ctypes for Perl" project. The project is being carried out for TPF under the auspices of the Google Summer of Code programme, and mentored by Reini Urban.

What's a ctypes?

'ctypes' is the Foreign Function Interface (FFI) library distributed with the Python core. It basically allows native C libraries to be called easily from Python; for module authors, it allows the wrapping of C libraries in pure Python.

This is obviously a powerful concept. Imagine a world where Perl module authors didn't need to use XS, and module consumers don't need to have a correctly configured compiler set up on their system. This is the purpose of the project: to create an easy, cross-platform, pure-Perl interface to native C libraries.

Implementations

ctypes is based on libffi. It's small, supports a wide range of systems, and has a very liberal license. It's been distributed with GCC for a number of years, used by gcj for interfacing between interpreted and compiled code.

From what I can gather, Python set the trend in dynamic languages using libffi. Looking at the success of the Python module, developers at Mozilla chose libffi to develop ctypes.jsm. Ruby-FFI uses it too, so there's plenty of prior art which will hopefully help me out.

The FFI problem hasn't been ignored in the Perl world. There's FFI.pm, the biggest disadvantage of which in my view is being built on libffcall, a library analogous to libffi but under the GPL (I don't think libffi was around at the time FFI.pm was written). It also sets out to provide a 'low-level' interface. P5NCI, on the other hand, is all about the lovely interfaces, but only allows up to four arguments passed to C functions, and doesn't yet support passing in pointers. C::Dynalib provides similar functionality to the other two modules; click here for the latest updates on its development. It's worth pointing out that none of these modules worked out of the box on Strawberry 5.10.1.

My proposed API rolls in features of several of the above implementations, particularly P5NCI and FFI.pm. I have indeed copied and pasted swathes from their POD pages (So what? Wanna fight about it?). I plan to also mimic C::DynaLib's acceptance of both positional & named parameters; examples are omitted below for succinctness.

1. Functional

use Ptypes;
# FFI.pm's interface of Absolute Freedom...
my $addr = (address of a C function)
my $signature = (function signature)
my $ret = Ptypes::call($addr, $signature, ...);

# Keeping things where you can see them...
my $library_path = Ptypes::find_lib( 'mathtastic' );
my $library = Ptypes::load_lib( $library_path );
my $double_func = Ptypes::load_func( $library, 'double_double', 'dd' );
my $ret = $double_func->( 1.0 );

# Supplying a Perl callback...
$ret = Ptypes::call($addr, $signature, $subref, ...)

2. Objectionable

use Ptypes;
my $lib = Ptypes->new( library => 'mathtastic' [, package => 'MyPackage' ] );
my $double_func = $lib->load_function( 'double_double', 'dd' );
my $ret = $double_func->( 1.0 );

# Exposing funcs directly in Perl namespaces...
$lib->install_function( 'double_int', 'ii' [, 'perl_sub_name', 'AnotherPackage' ] );
my $ret = AnotherPackage::double_int( 1 );

# or simply...
package AnotherPackage;
my $ret = double_int( 3 );

All fairly self-explanatory, perhaps apart from arguments like 'ii' or 'dd' - these strings describe return values and arguments for C functions in the same notation used by pack. In addition to the above, the module may provide mechanisms for manipulating C data types directly from Perl ($c = new Ptypes::char). To start off with though there'll be a fairly straight-forward / 'stupid' translation based on seeing what kind of data's in your SV*, for initial experimentation.

There's also some exciting stuff to do with GCC::TranslationUnit to tell you about, but details of that will wait till later. For now, I have some questions for you, the community:

  • How d'you like the API proposal above? Anything you'd add? Take out?
  • How does 'Ptypes' take you as a name for this malarky? Y'know, like ctypes, but for Perl. 'FFI' is already taken after all...

Don't want to gush here, but I'm so chuffed* to be working on this. I'm already learning loads, and I think it will save a lot of blood, sweat & tears for module authors and users in the future. I want to thank rurban for his guidance & help so far, and dukeleto and others for organising the The Perl Foundation's participation in GSoC and letting me participate!

I like to work log, so follow @doubious_code on Twitter to get far more information than you want about this project. I hope to be blogging pretty regularly too.

* For American-speakers, 'chuffed' is kinda equivalent to 'stoked'

Read More 6 comments
Comments: 6
+ -

  News: News: Rakudo Perl 6 development release #29 on 2010.05.23 6:50

Posted by brian_d_foy on 2010.05.23 6:50
Perl 6
colomon writes "On behalf of the Rakudo development team, I'm pleased to announce theMay 2010 development release of Rakudo Perl #29 "Erlangen". Rakudo is an implementation of Perl 6 on the Parrot Virtual Machine (see http://www.parrot.org./ The tarball for the May 2010 release is available from http://github.com/rakudo/rakudo/downloads .

Rakudo Perl follows a monthly release cycle, with each release named after a Perl Mongers group. The May 2010 release is code named "Erlangen" in recognition of Erlangen.pm and the Perl 6 talk that Moritz Lenz, one of our core developers, gave this month.

Some of the specific changes and improvements occurring with this release include:

* Lexical classes and roles were implemented. Additionally, anonymous classes which were never quite right in alpha are now implemented more correctly, and anonymous roles are also supported.

* Basic support for named enumerations of the form 'enum Weekday ' has been restored.

* First cut of use Foo:from and eval('foo', :lang); needs Blizkost[1] to be installed to work.

* Numeric / Real roles much closer to the spec now.

* As always, many additional small features and bug fixes make working with Rakudo more pleasant.

* Rakudo now passes 32,347 spectests. We estimate that there are about 39,500 tests in the test suite, so Rakudo passes about 82% of all tests.

For a more detailed list of changes see "docs/ChangeLog".

The development team thanks all of our contributors and sponsors for making Rakudo Perl possible, as well as those people who worked on parrot, the Perl 6 test suite and the specification.

The following people contributed to this release: Solomon Foster, Moritz Lenz, Jonathan Worthington, Martin Berends, chromatic, Carl Masak, snarkyboojum, Stefan O'Rear, Reini Urban, Jonathan Scott Duff, takadonet, Christoph Otto, isBEKaml, ash_, bubaflub, Jimmy Zhuo, Peter Lobsinger and Patrick Abi Salloum

If you would like to contribute, see http://rakudo.org/how-to-help , ask on the perl6-compiler@perl.org mailing list, or ask on IRC #perl6 on freenode.

The next release of Rakudo (#30) is scheduled for June 17, 2010. A list of the other planned release dates and code names for 2010 is available in the "docs/release_guide.pod" file. In general, Rakudo development releases are scheduled to occur two days after each Parrot monthly release. Parrot releases the third Tuesday of each month.

Have fun!

[1] http://github.com/jnthn/blizkost"
Read More 1 comments
Comments: 1
+ -

  BioPerl and the Google Summer of Code on 2010.03.26 21:07

Posted by brian_d_foy on 2010.03.26 21:07
User Journal
(original post here)

In addition to The Perl Foundation being accepted into GSoC 2010, BioPerl is now also part of the Google Summer of Code! The Open Bioinformatics Foundation, which also includes BioPython, BioRuby, and others, has been accepted into the Google Summer of Code for 2010. We are actively looking for students interested in OBF-related bioinformatics projects; new ideas are welcome. Project ideas and other details can be found here:

This isn't the first year BioPerl has been part of GSoC. A successful project was recently published by 2008 GSoC student Mira Han for developing a phyloXML parser for BioPerl.

Read More 0 comments

+ -

  Comment: Schwern will shoot you in the face (Score 1) on 2010.03.26 20:46

by brian_d_foy on 2010.03.26 20:46 (#71799)
Attached to: Some Facts About Schwern

That reminds me of your Perl book reviewing technique. If the bullet stops in the middle of the book, the book is too long.

Read More 6 comments
Comments: 6
+ -

  News: Nordic Perl Workshop 2010 on 2010.03.19 17:36

Posted by brian_d_foy on 2010.03.19 17:36
Events
Steinn E. Sigurdarson writes "This years Nordic Perl Workshop takes place the first weekend of May in Reykjavík, Iceland. This is the first time the event is held in Iceland, but hopefully not the last. Registration and more details are available on the workshop website."
Read More 0 comments

+ -

  yapc: OSDC.TW calls for papers on 2010.01.02 8:24

Posted by brian_d_foy on 2010.01.02 8:24
Others
hcchien writes "We are glad to announce the OSDC.TW 2010 will be at 2010/4/24-25 in Acadmeia Sinica, Taipei. So it's time to call for papers now. If you work for any interesting open source projects. It is a good time to introduce your projects to the open source developers in Taiwan. And sure, we would like to get the talks about the developing tips and experence sharing. The deadline of call of paper is 31th, January, 2010. And we accept three kind of talks:

tutorial: 3 hours, and we would provide the flight fee if the speakers are out of Taiwan. session: 1 hour.
lightning talk: 5 minute.

If you are interesting to submit the papers, please isending mail to submit@osdc.tw, and including the author intro and extract."
Read More 0 comments

+ -

  Journal: I'm twittering my Perl stuff at http://twitter.com/briandfoy on 2010.01.02 8:06

Journal by brian_d_foy on 2010.01.02 8:06
User Journal

I'll tweet at (http://twitter.com/briandfoy_perl) when I have something to say in 140 characters. I'll almost always use "Perl" when I post.

Read More 0 comments

+ -

  Effective Perl Programming master class at Frozen on 2010.01.01 8:32 brian_d_foy

Submitted by brian_d_foy on 2010.01.01 8:32
User Journal
At Frozen Perl 2010 in Minneapolis, I'm teaching a new master class based on my latest book, Effective Perl Programming, 2nd Edition. Perl has changed quite a bit since Joseph Hall wrote the first edition over 10 years ago. Josh McAdams and I have added a lot of new information as well as updated the existing material. In the one-day class for intermediate Perl programmers, I'll cover selected topics from the book, including:
  • Working with Unicode in Perl
  • Tricks with filehandles
  • New regex features in Perl 5.10 and later
  • Playing with pack()
  • Using closures to make things simpler
  • and other topics as time allows

Although the book hasn't been published yet, it is available for pre-order, and attendees to the class can get a sneak peek at the working manuscript as well as a soft copy of the course slides.

Read More 0 comments

+ -

  Journal: Effective Perl Programming master class at Frozen Perl on 2010.01.01 8:32

Journal by brian_d_foy on 2010.01.01 8:32
User Journal
At Frozen Perl 2010 in Minneapolis, I'm teaching a new master class based on my latest book, Effective Perl Programming, 2nd Edition. Perl has changed quite a bit since Joseph Hall wrote the first edition over 10 years ago. Josh McAdams and I have added a lot of new information as well as updated the existing material. In the one-day c
Read More 1 comments
Comments: 1
+ -

  Comment: I use the date when the date means something (Score 1) on 2010.01.01 8:29

by brian_d_foy on 2010.01.01 8:29 (#71461)
Attached to: Modules versioning

I started using a date as the major version with Business::ISBN::Data because the data are linked directly to particular releases from the ISBN Agency.

Beyond that I might use the date for something that is not a major version, but I just finished a project that had a pain point with version.pm because it used too many digits in the version, including major and minor versions, the svn revision, and build number. The svn version got to six digits (and maybe seven within a year in the shared repo), and the build number quickly got up to four digits.

Beyond that, as long as I know which one of a set of them is the most recent, I don't really care. :)

Read More 2 comments
Comments: 2
+ -

  Effective Perl Programming master class at Frozen Perl on 2010.01.01 6:58

Posted by brian_d_foy on 2010.01.01 6:58
User Journal
At Frozen Perl 2010 in Minneapolis, I'm teaching a new master class based on my latest book, Effective Perl Programming, 2nd Edition. Perl has changed quite a bit since Joseph Hall wrote the first edition over 10 years ago. Josh McAdams and I have added a lot of new information as well as updated the existing material. In the one-day class for intermediate Perl programmers, I'll cover selected topics from the book, including:
  • Working with Unicode in Perl
  • Tricks with filehandles
  • New regex features in Perl 5.10 and later
  • Playing with pack()
  • Using closures to make things simpler
  • and other topics as time allows

Although the book hasn't been published yet, it is available for pre-order, and attendees to the class can get a sneak peek at the working manuscript as well as a soft copy of the course slides.

Read More 1 comments
Comments: 1
+ -

  eumm-migrate - easy way to migrate to Module::Build on 2010.01.01 5:58

Posted by brian_d_foy on 2010.01.01 5:58
User Journal
Continuing celebration of Perl birthday...

ExtUtils::MakeMaker is a well known and well problematic module for installing Perl modules.

eumm-migrate is a tool I wrote to migrate from ExtUtils::MakeMaker to Module::Build. It executes Makefile.PL with fake ExtUtils::MakeMaker and rewrites all parameters for WriteMakefile into corresponding params of Module::Build->new. Calls to 'prompt' are also intercepted and corresponding 'prompt' is written to Build.PL. All other info should be ported manually.

Install App::EUMM::Migrate from CPAN and just run eumm-migrate.pl (it will be in your PATH) in directory with Makefile.PL. If you use Github, Internet connection is recommended.

eumm-migrate tries to automatically detect some properties like license, minimum Perl version required and repository used.

If someone needs it, I can also add a Module::Install writer.

P.S. If you want to just use new features of EU::MM, see eumm-upgrade.

Read More 0 comments

+ -

  Journal: What's your coolest Perl one-liner? on 2009.12.17 1:19

Journal by brian_d_foy on 2009.12.17 1:19
User Journal

Josh and I are finishing up Effective Perl Programming, 2nd Edition, and the last part to finish off is the item on Perl one-liners.

Read More 7 comments
Comments: 7
+ -

  News: Frozen Perl 2010 Call for Speakers on 2009.12.12 14:13

Posted by brian_d_foy on 2009.12.12 14:13
Events
olegm writes "It's that time of year again!

I am writing to advertise to all of you that Frozen Perl 2010 will be on February 5-7, 2010.

The call for speakers is open and I'd like extend an invite to speak to the community. Check it out at http://www.frozen-perl.org/mpw2010/cfs.html

We are also offering a hackthon on Sunday, and two classes, "Effective Perl Programming", taught by brian d foy and "Introduction to Moose" taught by Dave Rolsky on Friday February 5th.

Please submit your talks before Midnight on December 14th at http://www.frozen-perl.org/mpw2010/newtalk ."
Read More 0 comments

+ -

  Journal: I'm in Dublin on Sunday on 2009.10.22 15:13

Journal by brian_d_foy on 2009.10.22 15:13
User Journal

I kept meaning to post this, and I can't believe it's already this late in October.

Jonas Nielsen and I are going to be in Dublin, Ireland on Sunday because we're both running the marathon on Monday. If any local Perl Mongers want to get together for a drink on Sunday early evening, let me know. I'm staying about a mile from the marathon start and otherwise have no idea of the geography.

Read More 0 comments