I'm using Embperl for my development machine, but HTML::Embperl for 
production (and pre-release testing of course).  It'll be that way 
for a while, and in the meantime I have libraries that need to work 
regardless of which environment that are running.

With that in mind I wrote the following module, Embperlx::Util.pm. 
This lets you access all the standard special variables without 
worrying about which module called you.  Let me know if you find it 
useful, or have any problems with it.  So far I've only tested OUT 
and $escmode under both environments.

#
# 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;

CreateAliases();
sub CreateAliases {
     if (defined $Embperl::escmode) {
         Embperl::Util::CreateAliases();
     } elsif (defined $HTML::Embperl::escmode) {
         my $r = new Embperlx::Util::FakeReq();
         HTML::Embperl::Req::CreateAliases($r);
     } else {
         #!! Eventually we should fake some common variables here
         die("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 to 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;
}
1;
-- 

Kee Hinckley - Somewhere.Com, LLC
http://consulting.somewhere.com/
[EMAIL PROTECTED]

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to