[Israel.pm] help with "use base"

Mikhael Goikhman migo at homemail.com
Sun Aug 8 15:52:20 PDT 2004


On 08 Aug 2004 23:49:01 +0300, Scott Weisman wrote:
> 
> package cmf::control::web::front;
> use base 'cmf::control::web';
> 
> ===
> package cmf::control::web;
> use strict;
> 
> sub handler
> {
>     my $r = shift;
>     my $obj = bless {}, 'cmf::control::web::front';
>     $obj->session_check();
>     return Apache::OK;
> }
> 
> self session_check
> {
>     my $self = shift;
>     # session check code goes here
> }
> 
> 1;
> ===

This module dependancy is a bit strange. In one class you create an
instance of another class, that in turn inherits from the first one.
I don't see why you need an inheritance here. I may think about the
following possible way to break this circular dependancy. (Here I use
capitalized class names to distinuguish them from the method names.)

  CMF::Control::Web :: handler   - creates CMF::Web::Session object
  CMF::Web::Session :: check     - former session_check method

> [Sun Aug 08 13:22:52 2004] [error] [client 127.0.0.1] Can't locate 
> object method "session_check" via package "cmf::control::web::front" at 
> /opt/cmf/lib/cmf/control/web.pm line 57.

This error is expected, you can't call a class method without first
loading the class. To fix it, add this line to web.pm:

  use cmf::control::web::front;

This creates a circular "use", but Perl itself has no problem with it
(see "perldoc -f require" to find how it works). However your class
design may possibly look more clean without this redundant inheritance.

P.S. Interesting, you asked a very similar question a year ago:

  http://perl.org.il/pipermail/perl/2003-November/003474.html

Note that you use an old Perl, the new versions suggest the solution in
the error message: (perhaps you forgot to load 'class::name').

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list