----- Original Message -----
From: "David Oswald" <daosw...@gmail.com>
To: <inline@perl.org>
Sent: Monday, December 12, 2011 6:11 PM
Subject: Proof of concept: Math::Prime::FastSieve, uploaded to CPAN, uses
Inline::CPP
I just wanted to get a proof of concept ironed out demonstrating the
concept of a CPAN module using Inline::CPP (as opposed to some
old-school XS approach).
Math::Prime::FastSieve is on CPAN now -- or as soon as your local
mirrors pick it up. It implements the Primes Sieve of Eratosthenes
using a bit vector in C++, and serves it up to Perl via Inline::CPP.
This also provides me with a handy "proof of concept" for InlineX::CPP2XS.
(As I don't programme in C++, previous "proofs of concept" have used code
that is essentially C code.)
I can copy the cpp code from David's FastSieve.pm into ./src/FastSieve.cpp,
then run the following script:
###############################
use warnings;
use strict;
use InlineX::CPP2XS ('cpp2xs');
my $module_name = 'Math::Prime::FastSieve';
my $package_name = $module_name;
my $config_opts =
{'WRITE_PM' => 1,
'WRITE_MAKEFILE_PL' => 1,
'VERSION' => '0.02',
'EXPORT_OK_ALL' => 1,
};
cpp2xs($module_name, $package_name, $config_opts);
###############################
And that gives me (in my current directory) a CPP.map, FastSieve.pm (minus
documentation), FastSieve.xs, and Makefile.PL by which I can then build the
module in the usual way (ie. 'perl Makefile.PL', 'make') as a "normal" perl
extension, without *any* Inline dependency at all.
I can then run:
perl -Mblib -MMath::Prime::FastSieve="primes" -we "$p=primes(200);print
\"@$p\n\""
and see the primes up to and including 199 printed out. (Note that I'm using
the Win32 cmd.exe shell - which requires double quotes where other shells
might need single quotes.)
And btw, if anyone wants to try that, it's probably safest to do it in a
location *outside* of the Math-Prime-FastSieve-0.02 source tree.
Thanks David !!
Cheers,
Rob