in reply to Best way to implement Inline::C/Pure Perl function in a module?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best way to implement Inline::C/Pure Perl function in a module?
by uG (Scribe) on Oct 26, 2012 at 03:09 UTC | |
by syphilis (Archbishop) on Oct 26, 2012 at 05:04 UTC |