in reply to Best way to implement Inline::C/Pure Perl function in a module?
I think I would do it thusly:
Note also that those who have Inline::C can still access the pure-perl implementation of foo() if they wish, by directly calling bar().
Cheers,
Rob
If Inline::C is not available, that uses the pure-perl implementation of foo() and outputs:use strict; use warnings; eval { require Inline; Inline->import (C => Config => BUILD_NOISY => 1); require Inline; Inline->import (C =><<' EOC'); int foo() { warn("Using Inline\n"); return 42; } EOC }; # If Inline is unavailable, foo() simply calls # the sub bar() pure perl implementation. if($@) { *foo =\&bar; } sub bar { warn("Using Pure Perl Implementation\n"); return 42; } my $x = foo(); print "$x\n";
Otherwise, it uses the the Inline::C implementation of foo() and outputs:Using Pure Perl Implementation 42
NOTE: Running that script with Inline support will also output the C compilation report - but only for the *first* running, of course.Using Inline 42
Note also that those who have Inline::C can still access the pure-perl implementation of foo() if they wish, by directly calling bar().
Cheers,
Rob
In Section
Seekers of Perl Wisdom