Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / msys / O.pm
blob2ef91edbd92d71e7d582e8fefea4b89d45e089db
1 package O;
2 use B qw(minus_c save_BEGINs);
3 use Carp;
5 sub import {
6 my ($class, $backend, @options) = @_;
7 eval "use B::$backend ()";
8 if ($@) {
9 croak "use of backend $backend failed: $@";
11 my $compilesub = &{"B::${backend}::compile"}(@options);
12 if (ref($compilesub) eq "CODE") {
13 minus_c;
14 save_BEGINs;
15 eval 'CHECK { &$compilesub() }';
16 } else {
17 die $compilesub;
23 __END__
25 =head1 NAME
27 O - Generic interface to Perl Compiler backends
29 =head1 SYNOPSIS
31 perl -MO=Backend[,OPTIONS] foo.pl
33 =head1 DESCRIPTION
35 This is the module that is used as a frontend to the Perl Compiler.
37 =head1 CONVENTIONS
39 Most compiler backends use the following conventions: OPTIONS
40 consists of a comma-separated list of words (no white-space).
41 The C<-v> option usually puts the backend into verbose mode.
42 The C<-ofile> option generates output to B<file> instead of
43 stdout. The C<-D> option followed by various letters turns on
44 various internal debugging flags. See the documentation for the
45 desired backend (named C<B::Backend> for the example above) to
46 find out about that backend.
48 =head1 IMPLEMENTATION
50 This section is only necessary for those who want to write a
51 compiler backend module that can be used via this module.
53 The command-line mentioned in the SYNOPSIS section corresponds to
54 the Perl code
56 use O ("Backend", OPTIONS);
58 The C<import> function which that calls loads in the appropriate
59 C<B::Backend> module and calls the C<compile> function in that
60 package, passing it OPTIONS. That function is expected to return
61 a sub reference which we'll call CALLBACK. Next, the "compile-only"
62 flag is switched on (equivalent to the command-line option C<-c>)
63 and a CHECK block is registered which calls CALLBACK. Thus the main
64 Perl program mentioned on the command-line is read in, parsed and
65 compiled into internal syntax tree form. Since the C<-c> flag is
66 set, the program does not start running (excepting BEGIN blocks of
67 course) but the CALLBACK function registered by the compiler
68 backend is called.
70 In summary, a compiler backend module should be called "B::Foo"
71 for some foo and live in the appropriate directory for that name.
72 It should define a function called C<compile>. When the user types
74 perl -MO=Foo,OPTIONS foo.pl
76 that function is called and is passed those OPTIONS (split on
77 commas). It should return a sub ref to the main compilation function.
78 After the user's program is loaded and parsed, that returned sub ref
79 is invoked which can then go ahead and do the compilation, usually by
80 making use of the C<B> module's functionality.
82 =head1 AUTHOR
84 Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
86 =cut