IO::Socket::INET patch
[p5sagit/p5-mst-13.2.git] / ext / B / O.pm
CommitLineData
a798dbf2 1package O;
059a8bb7 2use B qw(minus_c save_BEGINs);
a798dbf2 3use Carp;
4
5sub import {
6 my ($class, $backend, @options) = @_;
7a9b44b9 7 eval q[
8 BEGIN {
9 minus_c;
10 save_BEGINs;
11 }
12
13 CHECK {
14 use B::].$backend.q[ ();
15 if ($@) {
16 croak "use of backend $backend failed: $@";
17 }
18
19
20 my $compilesub = &{"B::${backend}::compile"}(@options);
21 if (ref($compilesub) ne "CODE") {
22 die $compilesub;
23 }
24
25 &$compilesub();
26 }
27 ];
28 die $@ if $@;
a798dbf2 29}
30
311;
32
7f20e9dd 33__END__
34
35=head1 NAME
36
37O - Generic interface to Perl Compiler backends
38
39=head1 SYNOPSIS
40
41 perl -MO=Backend[,OPTIONS] foo.pl
42
43=head1 DESCRIPTION
44
1a52ab62 45This is the module that is used as a frontend to the Perl Compiler.
46
47=head1 CONVENTIONS
48
49Most compiler backends use the following conventions: OPTIONS
50consists of a comma-separated list of words (no white-space).
51The C<-v> option usually puts the backend into verbose mode.
52The C<-ofile> option generates output to B<file> instead of
53stdout. The C<-D> option followed by various letters turns on
54various internal debugging flags. See the documentation for the
55desired backend (named C<B::Backend> for the example above) to
56find out about that backend.
57
58=head1 IMPLEMENTATION
59
60This section is only necessary for those who want to write a
61compiler backend module that can be used via this module.
62
63The command-line mentioned in the SYNOPSIS section corresponds to
64the Perl code
65
66 use O ("Backend", OPTIONS);
67
68The C<import> function which that calls loads in the appropriate
69C<B::Backend> module and calls the C<compile> function in that
70package, passing it OPTIONS. That function is expected to return
71a sub reference which we'll call CALLBACK. Next, the "compile-only"
72flag is switched on (equivalent to the command-line option C<-c>)
7d30b5c4 73and a CHECK block is registered which calls CALLBACK. Thus the main
1a52ab62 74Perl program mentioned on the command-line is read in, parsed and
75compiled into internal syntax tree form. Since the C<-c> flag is
76set, the program does not start running (excepting BEGIN blocks of
77course) but the CALLBACK function registered by the compiler
78backend is called.
79
80In summary, a compiler backend module should be called "B::Foo"
81for some foo and live in the appropriate directory for that name.
82It should define a function called C<compile>. When the user types
83
84 perl -MO=Foo,OPTIONS foo.pl
85
86that function is called and is passed those OPTIONS (split on
87commas). It should return a sub ref to the main compilation function.
88After the user's program is loaded and parsed, that returned sub ref
89is invoked which can then go ahead and do the compilation, usually by
90making use of the C<B> module's functionality.
7f20e9dd 91
92=head1 AUTHOR
93
94Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
95
96=cut