perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kee Hinckley <>
Subject Re: Testing 2.x with production 1.x code
Date Sat, 05 Jul 2003 15:59:42 GMT
I wrote this a while ago, I haven't tested it on recent versions of 
2.0.  But feel free to try it.  My problem was that I had code which 
was doing things like using HTML::Embperl::OUT and it would break if 
used with 2.0.  The was to map each name space into a common generic 
space Embperlx::Util.  It doesn't deal with actually differences 
between the two (although you could make it do so), but it should 
allow you to make calls without worrying about which one is in use.
One problem is if you are using both libraries in the same shared
Apache address space this is going to default to Embperl::, which
may not be what you want.

# If you have a perl library that needs to access HTML::Embperl OR Embperl
# internals, this will create a name space that contains the necessary variables
# regardless of which package is currently in use.  This should make it easier
# to write libraries that work with both systems.
# Simple add "use Embperlx::Util" to your library, and then instead of
# accessing $HTML::Embperl::escmode or Embperl::OUT, refer to the variables
# as Embperlx::Util::varname and things should work fine in either context.
package Embperlx::Util;

sub CreateAliases {
    if (defined $Embperl::escmode) {
    } elsif (defined $HTML::Embperl::escmode) {
        my $r = new Embperlx::Util::FakeReq();
    } else {
        #!! Eventually we should fake some common variables here
        warn("Not running inside Embperl");

# Embperl has a clean CreateAliases call that inserts variables into
# the name space of the caller.  However HTML::Embperl expects to be
# passed a special HTML::Embperl::Req object.  Fortunately it only
# wants two methods out of that, and we can fake them both.
package Embperlx::Util::FakeReq;

sub new {
    my $pkg = shift;
    my $this = bless {}, $pkg;

    $this->{package} = caller;

    return $this;

sub CurrPackage {
    my $this = shift;

    return $this->{package};

sub ApacheReq {
    my $this = shift;

    return $HTML::Embperl::req_rec;

Kee Hinckley          Anti-Spam Service for your POP Account   Writings on Technology and Society

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message