develooper Front page | perl.perl5.porters | Postings from December 2003

Re: [DOCPATCH] BEGIN, CHECK, INIT, END explained more

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
December 3, 2003 05:23
Subject:
Re: [DOCPATCH] BEGIN, CHECK, INIT, END explained more
Message ID:
20031203141946.79f34b6f.rgarciasuarez@free.fr
Arthur Bergman wrote:
> >
> > What's needed IMO is yet another special code block -- COMPILED, START,
> > better names welcome -- run when the compilation of the said 
> > compilation
> > unit ends, regardless of the state of the main perl interpreter.
> >
> 
> No I disagree, I want to know apply the B::module magic after I require 
> something runtime too.

So write another B:: loader -- see below

> I guess what we need is a hook that gets called whenever a compilation 
> of a outer lexical scope (file, eval"") is completed.

A START block, then. So

    #!/usr/bin/perl
    eval q{
	BEGIN { print 1; }
	START { print 2; }
	CHECK { print 3; }
	INIT  { print 4; }
	        print 5;
	END   { print 6; }
    };
    print 7;
    __END__

would print "12576".

You could then write an alternative to O.pm that loads B::* from
a START block instead of from a CHECK block. The whole CHECK magic
is entirely done in O -- there's no reason to stop poeple from using
B:: modules apart from the O framework.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About