You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by cs...@fx.ro on 2003/08/05 10:55:52 UTC

PerlModule options?

Hi list,

One questions for the braves ;-)

As I understand, the directive

PerlModule Foo::Bar

loads the module but doesn't import the symbols since it is equivalent to
the use Foo::Bar (). Therefore I should use "use Foo::Bar" in each program
only to make the import.

Is there other way to load the module and import the symobols specified in
@EXPORT at mod_perl reloading time, without adding a special line in each
and every script using them?
Perhaps some options passed to PerlModule though adding (...) doesn't help
since PerlModule expects a list of modules.

Thanks a bunch,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net


RE: ModPerl - CGI in the same request phase

Posted by cs...@fx.ro.
Hi,

I'm in the happy position of finding myself a solution to my problem. Here
it is for anyone interested ...

PerlModule MyModules::Module1
<Directory /usr/local/apache1/protected>
    SetHandler perl-script
    PerlHandler MyModules::Module1
    PerlSendHeader Off
</Directory>

PerlModule Apache::PerlRun
<Directory /usr/local/apache1/protected/admin/>
    SetHandler perl-script
    PerlHandler MyModules::Module1 Apache::PerlRun
    Options +ExecCGI
</Directory>

And then, inside my handler, when I decide the users are alowed to run
scripts from the /admin directory I let them through by returning DECLINE,
if not I print an error page and return DONE to skip the second handler in
this phase.

Thanks anyway,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net

> -----Original Message-----
> From: csebe@fx.ro [mailto:csebe@fx.ro]
> Sent: Wednesday, August 06, 2003 2:33 PM
> To: modperl@perl.apache.org
> Subject: ModPerl - CGI in the same request phase
>
>
> Hi again everybody,
>
> I have the following interesting (I hope ;-) requirement. Sorry for this
> rather long posting.
> (mod_perl 1, Apache 1.3.27)
>
> I have a custom authentication & authorization handler of mine
> which is the
> king in a protected directory (and its subdirectories):
>
> PerlModule MyModules::Module1
> <Directory /usr/local/apache1/protected>
>     SetHandler perl-script
>     PerlHandler MyModules::Module1
>     PerlSendHeader Off
> </Directory>
>
> Then, for some users that I authenticate as SuperUsers, I should allow the
> execution of the administrative .cgi scripts in a subdir of this
> dir(/usr/local/apache1/ssl/protected/admin).
>
> (One solution would be to integrate the cgi-s logic into my handler but
> let's say want to leave them as simple CGI scripts.)
>
> I tried to use the Apache::PerlRun in the subdir like this:
> PerlModule Apache::PerlRun
> <Directory /usr/local/apache1/protected/admin>
> SetHandler perl-script
> PerlHandler Apache::PerlRun
> PerlSendHeader On
> Options ExecCGI
> </Directory>
>
> I tried also:
> <Directory /usr/local/apache1/ssl/protected/admin>
>     SetHandler cgi-script
>     Options +ExecCGI
> </Directory>
>
> The problem is it allows anybody to execute the cgi's since it's not going
> through my handler anymore (a "warn ..." statement inserted in my handler
> shows it's not executed when requesting /protected/admin/* files.)
>
> More generally: "how can I dynamically change a directory's handler during
> the same phase"
>
> I was thinking about using dynamic stacked handlers, something
> like: if the
> user is allowed in the admin section, my handler should push the
> cgi-script
> handler in the line of execution. However, the documentation says about
> stacking more custom created handlers and not those coming with Apache so
> I'm not sure how to do it.
>
> Thanks for your time,
>
> Lian Sebe, M.Sc.
> Freelance Analyst-Programmer
> www.programEz.net
>


ModPerl - CGI in the same request phase

Posted by cs...@fx.ro.
Hi again everybody,

I have the following interesting (I hope ;-) requirement. Sorry for this
rather long posting.
(mod_perl 1, Apache 1.3.27)

I have a custom authentication & authorization handler of mine which is the
king in a protected directory (and its subdirectories):

PerlModule MyModules::Module1
<Directory /usr/local/apache1/protected>
    SetHandler perl-script
    PerlHandler MyModules::Module1
    PerlSendHeader Off
</Directory>

Then, for some users that I authenticate as SuperUsers, I should allow the
execution of the administrative .cgi scripts in a subdir of this
dir(/usr/local/apache1/ssl/protected/admin).

(One solution would be to integrate the cgi-s logic into my handler but
let's say want to leave them as simple CGI scripts.)

I tried to use the Apache::PerlRun in the subdir like this:
PerlModule Apache::PerlRun
<Directory /usr/local/apache1/protected/admin>
SetHandler perl-script
PerlHandler Apache::PerlRun
PerlSendHeader On
Options ExecCGI
</Directory>

I tried also:
<Directory /usr/local/apache1/ssl/protected/admin>
    SetHandler cgi-script
    Options +ExecCGI
</Directory>

The problem is it allows anybody to execute the cgi's since it's not going
through my handler anymore (a "warn ..." statement inserted in my handler
shows it's not executed when requesting /protected/admin/* files.)

More generally: "how can I dynamically change a directory's handler during
the same phase"

I was thinking about using dynamic stacked handlers, something like: if the
user is allowed in the admin section, my handler should push the cgi-script
handler in the line of execution. However, the documentation says about
stacking more custom created handlers and not those coming with Apache so
I'm not sure how to do it.

Thanks for your time,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net


Re: PerlModule options?

Posted by Stas Bekman <st...@stason.org>.
csebe@fx.ro wrote:
> Hi again Stas & Perrin,
> 
> So, its a no-can-do then.
> 
> I'll keep putting the "use" in every module to import the symbols in the
> proper namespace.
> Alternatively I guess I could probably use the functions with fully qualfied
> name Apache::ReadConfig::myFunction(), however this would add extra typing
> and this is exactly what I was trying to escape from.
> 
> Thanks everyone for your time and kind answers.

You can define your export symbols in @EXPORT and they will be all exported by 
default, on 'use Module;'. See the Exporter manpage for more details.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


RE: PerlModule options?

Posted by cs...@fx.ro.
Hi again Stas & Perrin,

So, its a no-can-do then.

I'll keep putting the "use" in every module to import the symbols in the
proper namespace.
Alternatively I guess I could probably use the functions with fully qualfied
name Apache::ReadConfig::myFunction(), however this would add extra typing
and this is exactly what I was trying to escape from.

Thanks everyone for your time and kind answers.

Cheers,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net

> -----Original Message-----
> From: Stas Bekman [mailto:stas@stason.org]
> Sent: Tuesday, August 05, 2003 7:08 PM
> To: Mike P. Mikhailov
> Cc: csebe@fx.ro; modperl@perl.apache.org
> Subject: Re: PerlModule options?
>
>
> Mike P. Mikhailov wrote:
> > Hello csebe@fx.ro,
> >
> > Tuesday, August 05, 2003, 2:55:52 PM, you wrote:
> >
> > cfr> Hi list,
> >
> > cfr> One questions for the braves ;-)
> >
> > cfr> As I understand, the directive
> >
> > cfr> PerlModule Foo::Bar
> >
> > cfr> loads the module but doesn't import the symbols since it
> is equivalent to
> > cfr> the use Foo::Bar (). Therefore I should use "use Foo::Bar"
> in each program
> > cfr> only to make the import.
> >
> > cfr> Is there other way to load the module and import the
> symobols specified in
> > cfr> @EXPORT at mod_perl reloading time, without adding a
> special line in each
> > cfr> and every script using them?
> > cfr> Perhaps some options passed to PerlModule though adding
> (...) doesn't help
> > cfr> since PerlModule expects a list of modules.
>
> > I think this will work
> >
> > <perl>
> >       use Foo::Bar qw ( ... whatever you want to import ... );
> > </perl>
>
> I think Lian was asking how to import symbols into his
> scripts/handlers at the
> server startup.
>
> Lian, you *must* put the "special line" in each and every script
> you want the
> symbols to be exported to, because exporting happens inside the script's
> namespace, which is no main:: under Apache::Registry, but special
> for each script.
>
> You can preload registry scripts using Apache::RegistryLoader, but this
> doesn't remove the need for an explicit import.
>
>
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
>


Re: PerlModule options?

Posted by Stas Bekman <st...@stason.org>.
Mike P. Mikhailov wrote:
> Hello csebe@fx.ro,
> 
> Tuesday, August 05, 2003, 2:55:52 PM, you wrote:
> 
> cfr> Hi list,
> 
> cfr> One questions for the braves ;-)
> 
> cfr> As I understand, the directive
> 
> cfr> PerlModule Foo::Bar
> 
> cfr> loads the module but doesn't import the symbols since it is equivalent to
> cfr> the use Foo::Bar (). Therefore I should use "use Foo::Bar" in each program
> cfr> only to make the import.
> 
> cfr> Is there other way to load the module and import the symobols specified in
> cfr> @EXPORT at mod_perl reloading time, without adding a special line in each
> cfr> and every script using them?
> cfr> Perhaps some options passed to PerlModule though adding (...) doesn't help
> cfr> since PerlModule expects a list of modules.

> I think this will work
> 
> <perl>
>       use Foo::Bar qw ( ... whatever you want to import ... );
> </perl>

I think Lian was asking how to import symbols into his scripts/handlers at the 
server startup.

Lian, you *must* put the "special line" in each and every script you want the 
symbols to be exported to, because exporting happens inside the script's 
namespace, which is no main:: under Apache::Registry, but special for each script.

You can preload registry scripts using Apache::RegistryLoader, but this 
doesn't remove the need for an explicit import.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


RE: PerlModule options?

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-08-05 at 15:57, csebe@fx.ro wrote:
> Thanks for your answer, this should do it indeed. Super! Somehow I didn't
> think about perl sections...

Perl sections will not work for this.  If you do it there, the symbols
you want will only get imported into the Apache::ReadConfig namespace. 
You will not be able to call them in other scripts without importing
them there too.

- Perrin

RE: PerlModule options?

Posted by cs...@fx.ro.
Hello Mike,

Thanks for your answer, this should do it indeed. Super! Somehow I didn't
think about perl sections...

Thanks again,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net

> -----Original Message-----
> From: Mike P. Mikhailov [mailto:mike@sibtel.ru]
> Sent: Tuesday, August 05, 2003 2:23 PM
> To: csebe@fx.ro
> Cc: modperl@perl.apache.org
> Subject: Re: PerlModule options?
>
>
> Hello csebe@fx.ro,
>
> Tuesday, August 05, 2003, 2:55:52 PM, you wrote:
>
> cfr> Hi list,
>
> cfr> One questions for the braves ;-)
>
> cfr> As I understand, the directive
>
> cfr> PerlModule Foo::Bar
>
> cfr> loads the module but doesn't import the symbols since it is
> equivalent to
> cfr> the use Foo::Bar (). Therefore I should use "use Foo::Bar"
> in each program
> cfr> only to make the import.
>
> cfr> Is there other way to load the module and import the
> symobols specified in
> cfr> @EXPORT at mod_perl reloading time, without adding a special
> line in each
> cfr> and every script using them?
> cfr> Perhaps some options passed to PerlModule though adding
> (...) doesn't help
> cfr> since PerlModule expects a list of modules.
>
> cfr> Thanks a bunch,
>
> cfr> Lian Sebe, M.Sc.
> cfr> Freelance Analyst-Programmer
> cfr> www.programEz.net
>
> I think this will work
>
> <perl>
>       use Foo::Bar qw ( ... whatever you want to import ... );
> </perl>
>
> --
> WBR, Mike P. Mikhailov
>
> mailto: mike@sibtel.ru
> ICQ:    280990142
>
> I believe in God, only I spell it Nature.
>


Re: PerlModule options?

Posted by "Mike P. Mikhailov" <mi...@sibtel.ru>.
Hello csebe@fx.ro,

Tuesday, August 05, 2003, 2:55:52 PM, you wrote:

cfr> Hi list,

cfr> One questions for the braves ;-)

cfr> As I understand, the directive

cfr> PerlModule Foo::Bar

cfr> loads the module but doesn't import the symbols since it is equivalent to
cfr> the use Foo::Bar (). Therefore I should use "use Foo::Bar" in each program
cfr> only to make the import.

cfr> Is there other way to load the module and import the symobols specified in
cfr> @EXPORT at mod_perl reloading time, without adding a special line in each
cfr> and every script using them?
cfr> Perhaps some options passed to PerlModule though adding (...) doesn't help
cfr> since PerlModule expects a list of modules.

cfr> Thanks a bunch,

cfr> Lian Sebe, M.Sc.
cfr> Freelance Analyst-Programmer
cfr> www.programEz.net

I think this will work

<perl>
      use Foo::Bar qw ( ... whatever you want to import ... );
</perl>

-- 
WBR, Mike P. Mikhailov

mailto: mike@sibtel.ru
ICQ:    280990142

I believe in God, only I spell it Nature.


RE: PerlModule options?

Posted by cs...@fx.ro.
Hi Perrin,

I see your point. However I'm speaking about one simple templating module
exporting 2 functions that are used to generate HTML in every other module
on the server.

So it'll be pollution but bearable ;-)

Thank you,

Lian Sebe, M.Sc.
Freelance Analyst-Programmer
www.programEz.net

> -----Original Message-----
> From: Perrin Harkins [mailto:perrin@elem.com]
> Sent: Tuesday, August 05, 2003 8:29 PM
> To: csebe@fx.ro
> Cc: modperl@perl.apache.org
> Subject: Re: PerlModule options?
>
>
> On Tue, 2003-08-05 at 04:55, csebe@fx.ro wrote:
> > loads the module but doesn't import the symbols since it is
> equivalent to
> > the use Foo::Bar (). Therefore I should use "use Foo::Bar" in
> each program
> > only to make the import.
>
> Correct.
>
> > Is there other way to load the module and import the symobols
> specified in
> > @EXPORT at mod_perl reloading time, without adding a special
> line in each
> > and every script using them?
>
> No, that would be Bad.  By putting a "use Foo" in each module that wants
> to import functions from Foo, you are explicitly saying "please pollute
> my namespace" to Foo.  That sort of thing shouldn't happen unless you
> request it.
>
> > Perhaps some options passed to PerlModule though adding (...)
> doesn't help
> > since PerlModule expects a list of modules.
>
> There's no way it could since PerlModule has no way of knowing what
> namespaces you are going to want polluted.
>
> - Perrin
>


Re: PerlModule options?

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-08-05 at 04:55, csebe@fx.ro wrote:
> loads the module but doesn't import the symbols since it is equivalent to
> the use Foo::Bar (). Therefore I should use "use Foo::Bar" in each program
> only to make the import.

Correct.

> Is there other way to load the module and import the symobols specified in
> @EXPORT at mod_perl reloading time, without adding a special line in each
> and every script using them?

No, that would be Bad.  By putting a "use Foo" in each module that wants
to import functions from Foo, you are explicitly saying "please pollute
my namespace" to Foo.  That sort of thing shouldn't happen unless you
request it.

> Perhaps some options passed to PerlModule though adding (...) doesn't help
> since PerlModule expects a list of modules.

There's no way it could since PerlModule has no way of knowing what
namespaces you are going to want polluted.

- Perrin