1Inline(3)             User Contributed Perl Documentation            Inline(3)
2
3
4

NAME

6       Inline - Write Perl subroutines in other programming languages.
7

SYNOPSIS

9           use Inline C;
10
11           print "9 + 16 = ", add(9, 16), "\n";
12           print "9 - 16 = ", subtract(9, 16), "\n";
13
14           __END__
15           __C__
16           int add(int x, int y) {
17             return x + y;
18           }
19
20           int subtract(int x, int y) {
21             return x - y;
22           }
23

DESCRIPTION

25       The Inline module allows you to put source code from other programming
26       languages directly "inline" in a Perl script or module. The code is
27       automatically compiled as needed, and then loaded for immediate access
28       from Perl.
29
30       Inline saves you from the hassle of having to write and compile your
31       own glue code using facilities like XS or SWIG. Simply type the code
32       where you want it and run your Perl as normal. All the hairy details
33       are handled for you. The compilation and installation of your code
34       chunks all happen transparently; all you will notice is the delay of
35       compilation on the first run.
36
37       The Inline code only gets compiled the first time you run it (or
38       whenever it is modified) so you only take the performance hit once.
39       Code that is Inlined into distributed modules (like on the CPAN) will
40       get compiled when the module is installed, so the end user will never
41       notice the compilation time.
42
43       Best of all, it works the same on both Unix and Microsoft Windows. See
44       Inline-Support for support information.
45
46   Why Inline?
47       Do you want to know "Why would I use other languages in Perl?" or "Why
48       should I use Inline to do it?"? I'll try to answer both.
49
50       Why would I use other languages in Perl?
51           The most obvious reason is performance. For an interpreted
52           language, Perl is very fast. Many people will say "Anything Perl
53           can do, C can do faster". (They never mention the development time
54           :-) Anyway, you may be able to remove a bottleneck in your Perl
55           code by using another language, without having to write the entire
56           program in that language. This keeps your overall development time
57           down, because you're using Perl for all of the non-critical code.
58
59           Another reason is to access functionality from existing API-s that
60           use the language. Some of this code may only be available in binary
61           form.  But by creating small subroutines in the native language,
62           you can "glue" existing libraries to your Perl. As a user of the
63           CPAN, you know that code reuse is a good thing. So why throw away
64           those Fortran libraries just yet?
65
66           If you are using Inline with the C language, then you can access
67           the full internals of Perl itself. This opens up the floodgates to
68           both extreme power and peril.
69
70           Maybe the best reason is "Because you want to!". Diversity keeps
71           the world interesting. TMTOWTDI!
72
73       Why should I use Inline to do it?
74           There are already two major facilities for extending Perl with C.
75           They are XS and SWIG. Both are similar in their capabilities, at
76           least as far as Perl is concerned. And both of them are quite
77           difficult to learn compared to Inline.
78
79           There is a big fat learning curve involved with setting up and
80           using the XS environment. You need to get quite intimate with the
81           following docs:
82
83            * perlxs
84            * perlxstut
85            * perlapi
86            * perlguts
87            * perlmod
88            * h2xs
89            * xsubpp
90            * ExtUtils::MakeMaker
91
92           With Inline you can be up and running in minutes. There is a C
93           Cookbook with lots of short but complete programs that you can
94           extend to your real-life problems. No need to learn about the
95           complicated build process going on in the background. You don't
96           even need to compile the code yourself. Inline takes care of every
97           last detail except writing the C code.
98
99           Perl programmers cannot be bothered with silly things like
100           compiling.  "Tweak, Run, Tweak, Run" is our way of life. Inline
101           does all the dirty work for you.
102
103           Another advantage of Inline is that you can use it directly in a
104           script.  You can even use it in a Perl one-liner. With XS and SWIG,
105           you always set up an entirely separate module. Even if you only
106           have one or two functions. Inline makes easy things easy, and hard
107           things possible. Just like Perl.
108
109           Finally, Inline supports several programming languages (not just C
110           and C++). As of this writing, Inline has support for C, C++, Java,
111           Python, Ruby, Tcl, Assembler, Basic, Guile, Befunge, Octave, Awk,
112           BC, TT (Template Toolkit), WebChat and even PERL. New Inline
113           Language Support Modules (ILSMs) are regularly being added. See
114           Inline-API for details on how to create your own ILSM.
115

Using the Inline.pm Module

117       Inline is a little bit different than most of the Perl modules that you
118       are used to. It doesn't import any functions into your namespace and it
119       doesn't have any object oriented methods. Its entire interface (with
120       two minor exceptions) is specified through the 'use Inline ...'
121       command.
122
123       This section will explain all of the different ways to "use Inline". If
124       you want to begin using C with Inline immediately, see
125       Inline::C-Cookbook.
126
127   The Basics
128       The most basic form for using Inline is:
129
130           use Inline X => "X source code";
131
132       where 'X' is one of the supported Inline programming languages. The
133       second parameter identifies the source code that you want to bind to
134       Perl. The source code can be specified using any of the following
135       syntaxes:
136
137       The DATA Keyword.
138               use Inline Java => 'DATA';
139
140               # Perl code goes here ...
141
142               __DATA__
143               __Java__
144               /* Java code goes here ... */
145
146           The easiest and most visually clean way to specify your source code
147           in an Inline Perl program is to use the special "DATA" keyword.
148           This tells Inline to look for a special marker in your "DATA"
149           filehandle's input stream. In this example the special marker is
150           "__Java__", which is the programming language surrounded by double
151           underscores.
152
153           In case you've forgotten, the "DATA" pseudo file is comprised of
154           all the text after the "__END__" or "__DATA__" section of your
155           program. If you're working outside the "main" package, you'd best
156           use the "__DATA__" marker or else Inline will not find your code.
157
158           Using this scheme keeps your Perl code at the top, and all the ugly
159           Java stuff down below where it belongs. This is visually clean and
160           makes for more maintainable code. An excellent side benefit is that
161           you don't have to escape any characters like you might in a Perl
162           string. The source code is verbatim. For these reasons, I prefer
163           this method the most.
164
165           The only problem with this style is that since Perl can't read the
166           "DATA" filehandle until runtime, it obviously can't bind your
167           functions until runtime. The net effect of this is that you can't
168           use your Inline functions as barewords (without predeclaring them)
169           because Perl has no idea they exist during compile time.
170
171       The FILE and BELOW keywords.
172               use Inline::Files;
173               use Inline Java => 'FILE';
174
175               # Perl code goes here ...
176
177               __JAVA__
178               /* Java code goes here ... */
179
180           This is the newest method of specifying your source code. It makes
181           use of the Perl module "Inline::Files" written by Damian Conway.
182           The basic style and meaning are the same as for the "DATA" keyword,
183           but there are a few syntactic and semantic twists.
184
185           First, you must say 'use Inline::Files' before you 'use Inline'
186           code that needs those files. The special '"DATA"' keyword is
187           replaced by either '"FILE"' or '"BELOW"'. This allows for the bad
188           pun idiom of:
189
190               use Inline C => 'BELOW';
191
192           You can omit the "__DATA__" tag now. Inline::Files is a source
193           filter that will remove these sections from your program before
194           Perl compiles it. They are then available for Inline to make use
195           of. And since this can all be done at compile time, you don't have
196           to worry about the caveats of the 'DATA' keyword.
197
198           This module has a couple small gotchas. Since Inline::Files only
199           recognizes file markers with capital letters, you must specify the
200           capital form of your language name. Also, there is a startup time
201           penalty for using a source code filter.
202
203           At this point Inline::Files is alpha software and use of it is
204           experimental. Inline's integration of this module is also fledgling
205           at the time being. One of things I plan to do with Inline::Files is
206           to get line number info so when an extension doesn't compile, the
207           error messages will point to the correct source file and line
208           number.
209
210           My best advice is to use Inline::Files for testing (especially as
211           support for it improves), but use DATA for production and
212           distributed/CPAN code.
213
214       Strings
215               use Inline Java => <<'END';
216
217               /* Java code goes here ... */
218               END
219
220               # Perl code goes here ...
221
222           You also just specify the source code as a single string. A handy
223           way to write the string is to use Perl's "here document" style of
224           quoting. This is ok for small functions but can get unwieldy in the
225           large. On the other hand, the string variant probably has the least
226           startup penalty and all functions are bound at compile time.
227
228           If you wish to put the string into a scalar variable, please be
229           aware that the "use" statement is a compile time directive. As
230           such, all the variables it uses must also be set at compile time,
231           "before" the 'use Inline' statement. Here is one way to do it:
232
233               my $code;
234               BEGIN {
235                   $code = <<END;
236
237               /* Java code goes here ... */
238               END
239               }
240               use Inline Java => $code;
241
242               # Perl code goes here ...
243
244       The bind() Function
245           An alternative to using the BEGIN block method is to specify the
246           source code at run time using the 'Inline->bind()' method. (This is
247           one of the interface exceptions mentioned above) The "bind()"
248           method takes the same arguments as 'use Inline ...'.
249
250               my $code = <<END;
251
252               /* Java code goes here ... */
253               END
254
255               Inline->bind(Java => $code);
256
257           You can think of "bind()" as a way to "eval()" code in other
258           programming languages.
259
260           Although bind() is a powerful feature, it is not recommended for
261           use in Inline based modules. In fact, it won't work at all for
262           installable modules. See instructions below for creating modules
263           with Inline.
264
265       Other Methods
266           The source code for Inline can also be specified as an external
267           filename, a reference to a subroutine that returns source code, or
268           a reference to an array that contains lines of source code. (Note
269           that if the external source file is in the current directory it
270           must be specified with a leading './' - ie './file.ext' instead of
271           simply 'file.ext'.) These methods are less frequently used but may
272           be useful in some situations.
273
274       Shorthand
275           If you are using the 'DATA' or 'FILE' methods described above and
276           there are no extra parameters, you can omit the keyword altogether.
277           For example:
278
279               use Inline 'Java';
280
281               # Perl code goes here ...
282
283               __DATA__
284               __Java__
285               /* Java code goes here ... */
286
287           or
288
289               use Inline::Files;
290               use Inline 'Java';
291
292               # Perl code goes here ...
293
294               __JAVA__
295               /* Java code goes here ... */
296
297   More about the DATA Section
298       If you are writing a module, you can also use the DATA section for POD
299       and AutoLoader subroutines. Just be sure to put them before the first
300       Inline marker. If you install the helper module "Inline::Filters", you
301       can even use POD inside your Inline code. You just have to specify a
302       filter to strip it out.
303
304       You can also specify multiple Inline sections, possibly in different
305       programming languages. Here is another example:
306
307           # The module Foo.pm
308           package Foo;
309           use AutoLoader;
310
311           use Inline C;
312           use Inline C => DATA => FILTERS => 'Strip_POD';
313           use Inline Python;
314
315           1;
316
317           __DATA__
318
319           sub marine {
320               # This is an autoloaded subroutine
321           }
322
323           =head1 External subroutines
324
325           =cut
326
327           __C__
328           /* First C section */
329
330           __C__
331           /* Second C section */
332           =head1 My C Function
333
334           Some POD doc.
335
336           =cut
337
338           __Python__
339           """A Python Section"""
340
341       An important thing to remember is that you need to have one "use Inline
342       Foo => 'DATA'" for each "__Foo__" marker, and they must be in the same
343       order. This allows you to apply different configuration options to each
344       section.
345
346   Configuration Options
347       Inline trys to do the right thing as often as possible. But sometimes
348       you may need to override the default actions. This is easy to do.
349       Simply list the Inline configuration options after the regular Inline
350       parameters. All congiguration options are specified as (key, value)
351       pairs.
352
353           use Inline (C => 'DATA',
354                       DIRECTORY => './inline_dir',
355                       LIBS => '-lfoo',
356                       INC => '-I/foo/include',
357                       PREFIX => 'XXX_',
358                       WARNINGS => 0,
359                      );
360
361       You can also specify the configuration options on a separate Inline
362       call like this:
363
364           use Inline (C => Config =>
365                       DIRECTORY => './inline_dir',
366                       LIBS => '-lfoo',
367                       INC => '-I/foo/include',
368                       PREFIX => 'XXX_',
369                       WARNINGS => 0,
370                      );
371           use Inline C => <<'END_OF_C_CODE';
372
373       The special keyword 'Config' tells Inline that this is a configuration-
374       only call. No source code will be compiled or bound to Perl.
375
376       If you want to specify global configuration options that don't apply to
377       a particular language, just leave the language out of the call.  Like
378       this:
379
380           use Inline Config => WARNINGS => 0;
381
382       The Config options are inherited and additive. You can use as many
383       Config calls as you want. And you can apply different options to
384       different code sections. When a source code section is passed in,
385       Inline will apply whichever options have been specified up to that
386       point. Here is a complex configuration example:
387
388           use Inline (Config =>
389                       DIRECTORY => './inline_dir',
390                      );
391           use Inline (C => Config =>
392                       LIBS => '-lglobal',
393                      );
394           use Inline (C => 'DATA',         # First C Section
395                       LIBS => ['-llocal1', '-llocal2'],
396                      );
397           use Inline (Config =>
398                       WARNINGS => 0,
399                      );
400           use Inline (Python => 'DATA',    # First Python Section
401                       LIBS => '-lmypython1',
402                      );
403           use Inline (C => 'DATA',         # Second C Section
404                       LIBS => [undef, '-llocal3'],
405                      );
406
407       The first "Config" applies to all subsequent calls. The second "Config"
408       applies to all subsequent "C" sections (but not "Python" sections). In
409       the first "C" section, the external libraries "global", "local1" and
410       "local2" are used. (Most options allow either string or array ref
411       forms, and do the right thing.) The "Python" section does not use the
412       "global" library, but does use the same "DIRECTORY", and has warnings
413       turned off. The second "C" section only uses the "local3" library.
414       That's because a value of "undef" resets the additive behavior.
415
416       The "DIRECTORY" and "WARNINGS" options are generic Inline options. All
417       other options are language specific. To find out what the "C" options
418       do, see "Inline::C".
419
420   On and Off
421       If a particular config option has value options of 1 and 0, you can use
422       the ENABLE and DISABLE modifiers. In other words, this:
423
424           use Inline Config =>
425                      FORCE_BUILD => 1,
426                      CLEAN_AFTER_BUILD => 0;
427
428       could be reworded as:
429
430           use Inline Config =>
431                      ENABLE => FORCE_BUILD,
432                      DISABLE => CLEAN_AFTER_BUILD;
433
434   Playing 'with' Others
435       Inline has a special configuration syntax that tells it to get more
436       configuration options from other Perl modules. Here is an example:
437
438           use Inline with => 'Event';
439
440       This tells Inline to load the module "Event.pm" and ask it for
441       configuration information. Since "Event" has a C API of its own, it can
442       pass Inline all of the information it needs to be able to use "Event" C
443       callbacks seamlessly.
444
445       That means that you don't need to specify the typemaps, shared
446       libraries, include files and other information required to get this to
447       work.
448
449       You can specify a single module or a list of them. Like:
450
451           use Inline with => qw(Event Foo Bar);
452
453       Currently, "Event" is the only module that works with Inline.
454
455   Inline Shortcuts
456       Inline lets you set many configuration options from the command line.
457       These options are called 'shortcuts'. They can be very handy,
458       especially when you only want to set the options temporarily, for say,
459       debugging.
460
461       For instance, to get some general information about your Inline code in
462       the script "Foo.pl", use the command:
463
464           perl -MInline=INFO Foo.pl
465
466       If you want to force your code to compile, even if its already done,
467       use:
468
469           perl -MInline=FORCE Foo.pl
470
471       If you want to do both, use:
472
473           perl -MInline=INFO -MInline=FORCE Foo.pl
474
475       or better yet:
476
477           perl -MInline=INFO,FORCE Foo.pl
478
479   The Inline DIRECTORY
480       Inline needs a place to build your code and to install the results of
481       the build. It uses a single directory named '.Inline/' under normal
482       circumstances. If you create this directory in your home directory, the
483       current directory or in the directory where your program resides,
484       Inline will find and use it. You can also specify it in the environment
485       variable "PERL_INLINE_DIRECTORY" or directly in your program, by using
486       the "DIRECTORY" keyword option. If Inline cannot find the directory in
487       any of these places it will create a '_Inline/' directory in either
488       your current directory or the directory where your script resides.
489
490       One of the key factors to using Inline successfully, is understanding
491       this directory. When developing code it is usually best to create this
492       directory (or let Inline do it) in your current directory. Remember
493       that there is nothing sacred about this directory except that it holds
494       your compiled code. Feel free to delete it at any time. Inline will
495       simply start from scratch and recompile your code on the next run. If
496       you have several programs that you want to force to recompile, just
497       delete your '.Inline/' directory.
498
499       It is probably best to have a separate '.Inline/' directory for each
500       project that you are working on. You may want to keep stable code in
501       the <.Inline/> in your home directory. On multi-user systems, each user
502       should have their own '.Inline/' directories. It could be a security
503       risk to put the directory in a shared place like "/tmp/".
504
505   Debugging Inline Errors
506       All programmers make mistakes. When you make a mistake with Inline,
507       like writing bad C code, you'll get a big error report on your screen.
508       This report tells you where to look to do the debugging. Some languages
509       may also dump out the error messages generated from the build.
510
511       When Inline needs to build something it creates a subdirectory under
512       your "DIRECTORY/build/" directory. This is where it writes all the
513       components it needs to build your extension. Things like XS files,
514       Makefiles and output log files.
515
516       If everything goes OK, Inline will delete this subdirectory. If there
517       is an error, Inline will leave the directory intact and print its
518       location.  The idea is that you are supposed to go into that directory
519       and figure out what happened.
520
521       Read the doc for your particular Inline Language Support Module for
522       more information.
523
524   The 'config' Registry File
525       Inline keeps a cached file of all of the Inline Language Support
526       Module's meta data in a file called "config". This file can be found in
527       your "DIRECTORY" directory. If the file does not exist, Inline creates
528       a new one. It will search your system for any module beginning with
529       "Inline::". It will then call that module's "register()" method to get
530       useful information for future invocations.
531
532       Whenever you add a new ILSM, you should delete this file so that Inline
533       will auto-discover your newly installed language module. (This should
534       no longer be necessary as of Inline-0.49.)
535

Configuration Options

537       This section lists all of the generic Inline configuration options. For
538       language specific configuration, see the doc for that language.
539
540   DIRECTORY
541       The "DIRECTORY" config option is the directory that Inline uses to both
542       build and install an extension.
543
544       Normally Inline will search in a bunch of known places for a directory
545       called '.Inline/'. Failing that, it will create a directory called
546       '_Inline/'
547
548       If you want to specify your own directory, use this configuration
549       option.
550
551       Note that you must create the "DIRECTORY" directory yourself. Inline
552       will not do it for you.
553
554   NAME
555       You can use this option to set the name of your Inline extension object
556       module. For example:
557
558           use Inline C => 'DATA',
559                      NAME => 'Foo::Bar';
560
561       would cause your C code to be compiled in to the object:
562
563           lib/auto/Foo/Bar/Bar.so
564           lib/auto/Foo/Bar/Bar.inl
565
566       (The .inl component contains dependency information to make sure the
567       source code is in sync with the executable)
568
569       If you don't use NAME, Inline will pick a name for you based on your
570       program name or package name. In this case, Inline will also enable the
571       AUTONAME option which mangles in a small piece of the MD5 fingerprint
572       into your object name, to make it unique.
573
574   AUTONAME
575       This option is enabled whenever the NAME parameter is not specified. To
576       disable it say:
577
578           use Inline C => 'DATA',
579                      DISABLE => 'AUTONAME';
580
581       AUTONAME mangles in enough of the MD5 fingerprint to make your module
582       name unique. Objects created with AUTONAME will never get replaced.
583       That also means they will never get cleaned up automatically.
584
585       AUTONAME is very useful for small throw away scripts. For more serious
586       things, always use the NAME option.
587
588   VERSION
589       Specifies the version number of the Inline extension object. It is used
590       only for modules, and it must match the global variable $VERSION.
591       Additionally, this option should used if (and only if) a module is
592       being set up to be installed permanently into the Perl sitelib tree.
593       Inline will croak if you use it otherwise.
594
595       The presence of the VERSION parameter is the official way to let Inline
596       know that your code is an installable/installed module. Inline will
597       never generate an object in the temporary cache (_Inline/ directory) if
598       VERSION is set. It will also never try to recompile a module that was
599       installed into someone's Perl site tree.
600
601       So the basic rule is develop without VERSION, and deliver with VERSION.
602
603   WITH
604       "WITH" can also be used as a configuration option instead of using the
605       special 'with' syntax. Do this if you want to use different sections of
606       Inline code with different modules. (Probably a very rare usage)
607
608           use Event;
609           use Inline C => DATA => WITH => 'Event';
610
611       Modules specified using the config form of "WITH" will not be
612       automatically required. You must "use" them yourself.
613
614   GLOBAL_LOAD
615       This option is for compiled languages only. It tells Inline to tell
616       DynaLoader to load an object file in such a way that its symbols can be
617       dynamically resolved by other object files. May not work on all
618       platforms. See the "GLOBAL" shortcut below.
619
620   UNTAINT
621       You can use this option whenever you use Perl's "-T" switch, for taint
622       checking. This option tells Inline to blindly untaint all tainted
623       variables. (This is generally considerd to be an appallingly insecure
624       thing to do, and not to be recommended - but the option is there for
625       you to use if you want. Please consider using something other than
626       Inline for scripts that need taint checking.)  It also turns on
627       SAFEMODE by default. See the "UNTAINT" shortcut below.  You will see
628       warnings about blindly untainting fields in both %ENV and Inline
629       objects. If you want to silence these warnings, set the Config option
630       NO_UNTAINT_WARN => 1.  There can be some problems untainting Inline
631       scripts where older versions of Cwd, such as those that shipped with
632       early versions of perl-5.8 (and earlier), are installed. Updating Cwd
633       will probably solve these problems.
634
635   SAFEMODE
636       Perform extra safety checking, in an attempt to thwart malicious code.
637       This option cannot guarantee security, but it does turn on all the
638       currently implemented checks. (Currently, the only "currently
639       implemented check" is to ensure that the "DIRECTORY" option has also
640       been used.)
641
642       There is a slight startup penalty by using SAFEMODE. Also, using
643       UNTAINT automatically turns this option on. If you need your code to
644       start faster under "-T" (taint) checking, you'll need to turn this
645       option off manually. Only do this if you are not worried about security
646       risks. See the "UNSAFE" shortcut below.
647
648   FORCE_BUILD
649       Makes Inline build (compile) the source code every time the program is
650       run. The default is 0. See the "FORCE" shortcut below.
651
652   BUILD_NOISY
653       Tells ILSMs that they should dump build messages to the terminal rather
654       than be silent about all the build details.
655
656   BUILD_TIMERS
657       Tells ILSMs to print timing information about how long each build phase
658       took. Usually requires "Time::HiRes".
659
660   CLEAN_AFTER_BUILD
661       Tells Inline to clean up the current build area if the build was
662       successful. Sometimes you want to DISABLE this for debugging. Default
663       is 1. See the "NOCLEAN" shortcut below.
664
665   CLEAN_BUILD_AREA
666       Tells Inline to clean up the old build areas within the entire Inline
667       DIRECTORY. Default is 0. See the "CLEAN" shortcut below.
668
669   PRINT_INFO
670       Tells Inline to print various information about the source code.
671       Default is 0. See the "INFO" shortcut below.
672
673   PRINT_VERSION
674       Tells Inline to print Version info about itself. Default is 0. See the
675       "VERSION" shortcut below.
676
677   REPORTBUG
678       Puts Inline into 'REPORTBUG' mode, which is what you want if you desire
679       to report a bug.
680
681   REWRITE_CONFIG_FILE
682       Default is 0, but setting 'REWRITE_CONFIG_FILE => 1' will mean that the
683       existing configuration file in the Inline DIRECTORY will be
684       overwritten.  (This is useful if the existing config file is not up to
685       date as regards supported languages.)
686
687   WARNINGS
688       This option tells Inline whether to print certain warnings. Default is
689       1.
690

Inline Configuration Shortcuts

692       This is a list of all the shorcut configuration options currently
693       available for Inline. Specify them from the command line when running
694       Inline scripts.
695
696           perl -MInline=NOCLEAN inline_script.pl
697
698       or
699
700           perl -MInline=Info,force,NoClean inline_script.pl
701
702       You can specify multiple shortcuts separated by commas. They are not
703       case sensitive. You can also specify shorcuts inside the Inline program
704       like this:
705
706           use Inline 'Info', 'Force', 'Noclean';
707
708       NOTE: If a 'use Inline' statement is used to set shortcuts, it can not
709       be used for additional purposes.
710
711       CLEAN
712           Tells Inline to remove any build directories that may be lying
713           around in your build area. Normally these directories get removed
714           immediately after a successful build. Exceptions are when the build
715           fails, or when you use the NOCLEAN or REPORTBUG options.
716
717       FORCE
718           Forces the code to be recompiled, even if everything is up to date.
719
720       GLOBAL
721           Turns on the GLOBAL_LOAD option.
722
723       INFO
724           This is a very useful option when you want to know what's going on
725           under the hood. It tells Inline to print helpful information to
726           "STDERR".  Among the things that get printed is a list of which
727           Inline functions were successfully bound to Perl.
728
729       NOCLEAN
730           Tells Inline to leave the build files after compiling.
731
732       NOISY
733           Use the BUILD_NOISY option to print messages during a build.
734
735       REPORTBUG
736           Puts Inline into 'REPORTBUG' mode, which does special processing
737           when you want to report a bug. REPORTBUG also automatically forces
738           a build, and doesn't clean up afterwards. This is so that you can
739           tar and mail the build directory to me. REPORTBUG will print exact
740           instructions on what to do. Please read and follow them carefully.
741
742           NOTE: REPORTBUG informs you to use the tar command. If your system
743           does not have tar, please use the equivalent "zip" command.
744
745       SAFE
746           Turns SAFEMODE on. UNTAINT will turn this on automatically. While
747           this mode performs extra security checking, it does not guarantee
748           safety.
749
750       SITE_INSTALL
751           This parameter used to be used for creating installable Inline
752           modules.  It has been removed from Inline altogether and replaced
753           with a much simpler and more powerful mechanism,
754           "Inline::MakeMaker". See the section below on how to create modules
755           with Inline.
756
757       _TESTING
758           Used internally by C/t/09parser.t and C/t/10callback.t(in the
759           Inline::C test suite). Setting this option with Inline::C will mean
760           that files named 'parser_id' and 'void_test' are created in the
761           ./Inline_test directory, creating that directory if it doesn't
762           already exist. The files (but not the ./Inline_test directory) are
763           cleaned up by calling Inline::C::_testing_cleanup().  Also used by
764           t/06rewrite_config.t to trigger a warning.
765
766       TIMERS
767           Turn on BUILD_TIMERS to get extra diagnostic info about builds.
768
769       UNSAFE
770           Turns SAFEMODE off. Use this in combination with UNTAINT for
771           slightly faster startup time under "-T". Only use this if you are
772           sure the environment is safe.
773
774       UNTAINT
775           Turn the UNTAINT option on. Used with "-T" switch.  In terms of
776           secure practices, this is definitely *not* a recommended way of
777           dealing with taint checking, but it's the *only* option currently
778           available with Inline. Use it at your own risk.
779
780       VERSION
781           Tells Inline to report its release version.
782

Writing Modules with Inline

784       Writing CPAN modules that use C code is easy with Inline. Let's say
785       that you wanted to write a module called "Math::Simple". Start by using
786       the following command:
787
788           h2xs -PAXn Math::Simple
789
790       This will generate a bunch of files that form a skeleton of what you
791       need for a distributable module. (Read the h2xs manpage to find out
792       what the options do) Next, modify the "Simple.pm" file to look like
793       this:
794
795           package Math::Simple;
796           $VERSION = '1.23';
797
798           use base 'Exporter';
799           @EXPORT_OK = qw(add subtract);
800           use strict;
801
802           use Inline C => 'DATA',
803                      VERSION => '1.23',
804                      NAME => 'Math::Simple';
805
806           # The following Inline->init() call is optional - see below for more info.
807           #Inline->init();
808
809           1;
810
811           __DATA__
812
813           =pod
814
815           =cut
816
817           __C__
818           int add(int x, int y) {
819             return x + y;
820           }
821
822           int subtract(int x, int y) {
823             return x - y;
824           }
825
826       The important things to note here are that you must specify a "NAME"
827       and "VERSION" parameter. The "NAME" must match your module's package
828       name. The "VERSION" parameter must match your module's $VERSION
829       variable and they must be of the form "/^\d\.\d\d$/".
830
831       NOTE: These are Inline's sanity checks to make sure you know what
832       you're doing before uploading your code to CPAN. They insure that once
833       the module has been installed on someone's system, the module would not
834       get automatically recompiled for any reason. This makes Inline based
835       modules work in exactly the same manner as XS based ones.
836
837       Finally, you need to modify the Makefile.PL. Simply change:
838
839           use ExtUtils::MakeMaker;
840
841       to
842
843           use Inline::MakeMaker;
844
845       And, in order that the module build work correctly in the cpan shell,
846       add the following directive to the Makefile.PL's WriteMakefile():
847
848               CONFIGURE_REQUIRES  =>  {
849                   'Inline::MakeMaker'     => 0.45,
850                   'ExtUtils::MakeMaker'   => 6.52,
851               },
852
853       This "CONFIGURE_REQUIRES" directive ensures that the cpan shell will
854       install Inline on the user's machine (if it's not already present)
855       before building your Inline-based module.  Specifying of
856       "ExtUtils::MakeMaker => 6.52," is optional, and can be omitted if you
857       like. It ensures only that some harmless warnings relating to the
858       "CONFIGURE_REQUIRES" directive won't be emitted during the building of
859       the module. It also means, of course, that ExtUtils::Makemaker will
860       first be updated on the user's machine unless the user already has
861       version 6.52 or later.
862
863       If the "Inline->init();" is not done then, having installed
864       Math::Simple, a warning that "One or more DATA sections were not
865       processed by Inline" will appear when (and only when) Math::Simple is
866       loaded by a "require call. It's a harmless warning - and if you're
867       prepared to live with it, then there's no need to make the
868       "Inline->init();" call.
869
870       When the person installing "Math::Simple" does a ""make"", the
871       generated Makefile will invoke Inline in such a way that the C code
872       will be compiled and the executable code will be placed into the
873       "./blib" directory. Then when a ""make install"" is done, the module
874       will be copied into the appropriate Perl sitelib directory (which is
875       where an installed module should go).
876
877       Now all you need to do is:
878
879           perl Makefile.PL
880           make dist
881
882       That will generate the file "Math-Simple-0.20.tar.gz" which is a
883       distributable package. (It will also generate some harmless warnings in
884       relation to "CONFIGURE_REQUIRES" unless the version of your
885       ExtUtils::MakeMaker is 6.52 or later.) That's all there is to it.
886
887       IMPORTANT NOTE: Although the above steps will produce a workable
888       module, you still have a few more responsibilities as a budding new
889       CPAN author. You need to write lots of documentation and write lots of
890       tests. Take a look at some of the better CPAN modules for ideas on
891       creating a killer test harness.  Actually, don't listen to me, go read
892       these:
893
894           perldoc perlnewmod
895           http://www.cpan.org/modules/04pause.html
896           http://www.cpan.org/modules/00modlist.long.html
897

How Inline Works

899       In reality, Inline just automates everything you would need to do if
900       you were going to do it by hand (using XS, etc).
901
902       Inline performs the following steps:
903
904       1) Receive the Source Code
905           Inline gets the source code from your script or module with a
906           statements like the following:
907
908               use Inline C => "Source-Code";
909
910           or
911
912               use Inline;
913               bind Inline C => "Source-Code";
914
915           where "C" is the programming language of the source code, and
916           "Source-Code" is a string, a file name, an array reference, or the
917           special 'DATA' keyword.
918
919           Since Inline is coded in a ""use"" statement, everything is done
920           during Perl's compile time. If anything needs to be done that will
921           affect the "Source-Code", it needs to be done in a "BEGIN" block
922           that is before the ""use Inline ..."" statement. If you really need
923           to specify code to Inline at runtime, you can use the "bind()"
924           method.
925
926           Source code that is stowed in the 'DATA' section of your code, is
927           read in by an "INIT" subroutine in Inline. That's because the
928           "DATA" filehandle is not available at compile time.
929
930       2) Check if the Source Code has been Built
931           Inline only needs to build the source code if it has not yet been
932           built.  It accomplishes this seemingly magical task in an extremely
933           simple and straightforward manner. It runs the source text through
934           the "Digest::MD5" module to produce a 128-bit "fingerprint" which
935           is virtually unique. The fingerprint along with a bunch of other
936           contingency information is stored in a ".inl" file that sits next
937           to your executable object. For instance, the "C" code from a script
938           called "example.pl" might create these files:
939
940               example_pl_3a9a.so
941               example_pl_3a9a.inl
942
943           If all the contingency information matches the values stored in the
944           ".inl" file, then proceed to step 8. (No compilation is necessary)
945
946       3) Find a Place to Build and Install
947           At this point Inline knows it needs to build the source code. The
948           first thing to figure out is where to create the great big mess
949           associated with compilation, and where to put the object when it's
950           done.
951
952           By default Inline will try to build and install under the first
953           place that meets one of the following conditions:
954
955               A) The DIRECTORY= config option; if specified
956               B) The PERL_INLINE_DIRECTORY environment variable; if set
957               C) .Inline/ (in current directory); if exists and $PWD != $HOME
958               D) bin/.Inline/ (in directory of your script); if exists
959               E) ~/.Inline/; if exists
960               F) ./_Inline/; if exists
961               G) bin/_Inline; if exists
962               H) Create ./_Inline/; if possible
963               I) Create bin/_Inline/; if possible
964
965           Failing that, Inline will croak. This is rare and easily remedied
966           by just making a directory that Inline will use.
967
968           If the PERL_INSTALL_ROOT Environment Variable has been set, you
969           will need to make special provision for that if the 'make install'
970           phase of your Inline scripts are to succeed.
971
972           If the module option is being compiled for permanent installation,
973           then Inline will only use "./_Inline/" to build in, and the
974           $Config{installsitearch} directory to install the executable in.
975           This action is caused by Inline::MakeMaker, and is intended to be
976           used in modules that are to be distributed on the CPAN, so that
977           they get installed in the proper place.
978
979       4) Parse the Source for Semantic Cues
980           Inline::C uses the module "Parse::RecDescent" to parse through your
981           chunks of C source code and look for things that it can create run-
982           time bindings to. In "C" it looks for all of the function
983           definitions and breaks them down into names and data types. These
984           elements are used to correctly bind the "C" function to a "Perl"
985           subroutine. Other Inline languages like Python and Java actually
986           use the "python" and "javac" modules to parse the Inline code.
987
988       5) Create the Build Environment
989           Now Inline can take all of the gathered information and create an
990           environment to build your source code into an executable. Without
991           going into all the details, it just creates the appropriate
992           directories, creates the appropriate source files including an XS
993           file (for C) and a "Makefile.PL".
994
995       6) Build the Code and Install the Executable
996           The planets are in alignment. Now for the easy part. Inline just
997           does what you would do to install a module. ""perl Makefile.PL &&
998           make && make test && make install"". If something goes awry, Inline
999           will croak with a message indicating where to look for more info.
1000
1001       7) Tidy Up
1002           By default, Inline will remove all of the mess created by the build
1003           process, assuming that everything worked. If the build fails,
1004           Inline will leave everything intact, so that you can debug your
1005           errors. Setting the "NOCLEAN" shortcut option will also stop Inline
1006           from cleaning up.
1007
1008       8) DynaLoad the Executable
1009           For C (and C++), Inline uses the "DynaLoader::bootstrap" method to
1010           pull your external module into "Perl" space. Now you can call all
1011           of your external functions like Perl subroutines.
1012
1013           Other languages like Python and Java, provide their own loaders.
1014

SEE ALSO

1016       For information about using Inline with C see Inline::C.
1017
1018       For sample programs using Inline with C see Inline::C-Cookbook.
1019
1020       For "Formerly Answered Questions" about Inline, see Inline-FAQ.
1021
1022       For information on supported languages and platforms see Inline-
1023       Support.
1024
1025       For information on writing your own Inline Language Support Module, see
1026       Inline-API.
1027
1028       Inline's mailing list is inline@perl.org
1029
1030       To subscribe, send email to inline-subscribe@perl.org
1031

BUGS AND DEFICIENCIES

1033       When reporting a bug, please do the following:
1034
1035        - Put "use Inline REPORTBUG;" at the top of your code, or
1036          use the command line option "perl -MInline=REPORTBUG ...".
1037        - Run your code.
1038        - Follow the printed directions.
1039

AUTHOR

1041       Brian Ingerson <INGY@cpan.org>
1042
1043       Neil Watkiss <NEILW@cpan.org> is the author of "Inline::CPP",
1044       "Inline::Python", "Inline::Ruby", "Inline::ASM", "Inline::Struct" and
1045       "Inline::Filters". He is known in the innermost Inline circles as the
1046       "Boy Wonder".
1047
1048       Sisyphus <sisyphus@cpan.org> fixed some bugs and is current co-
1049       maintainer.
1050
1052       Copyright (c) 2000-2002. Brian Ingerson.
1053
1054       Copyright (c) 2008, 2010-2013. Sisyphus.
1055
1056       This program is free software; you can redistribute it and/or modify it
1057       under the same terms as Perl itself.
1058
1059       See http://www.perl.com/perl/misc/Artistic.html
1060
1061
1062
1063perl v5.16.3                      2013-04-10                         Inline(3)
Impressum