Re: Please review new Perl 5 Module List

Gisle.Aas@nr.no
Tue, 28 Feb 95 11:15:50 +0100


m.koster@nexor.co.uk writes:
> And all of a sudden things move fast :-)

We'll see :-(

> > > I do miss some of the higher level error management functions I have,
> > > for example to translate codes to mnemonics (and error messages).
> > 
> > Do you mean callbacks or some functions to do:
> > 
> >   $WWW::RespMessage{WWW::RC_SOMETHING}
> > 
> > stuff.
> 
> I need to lookup rc_code->mnemonic. Say I do a get, and receive 600,
> then I need to be able to translate that to RC_WHATEVER, if these
> mnemonics are used as indices into hashes. This might be another
> argument not to use subs to define the constants.
> 
> I also want to be able to do WWW::isRedirect(600) etc to group
> errors without having to check for all possible values.

The alternatives for return value from WWW::request are (as I see it):

   1) an integer value and provide some package functions:
        WWW::mnemonic($rc)
        WWW::isRedirect($rc)

   2) a ref to some object with methods like
        $rc->code
        $rc->mnemonic
        $rc->isRedirect

If we return an object, then we might stuff more into it, like the
returned headers and the content.  I think I like option 2.

> > >                                                               With
> > > the URL I'd prefer using $url->scheme to $url->FETCH(SCHEME). Maybe
> > > I've been programming C++ too long, but I think an OO approach looks
> > > more obvious than opaque hashes, and I don't think it buys you
> > > anything. This is a farily major point interface-wise :-)
> > 
> > But then we would need two methods for each attribute:
> > 
> >    $scheme = $url->get_scheme;
> > and
> >    $url->set_scheme($scheme);
> 
> Not really:
> 
> sub scheme {
>    my($this, $scheme) = @_;
>    my($oldscheme) = $this->{'scheme'};
>    $this->{'scheme'} = $scheme if (defined $scheme);
>    return($oldscheme);
> }

Yes, I though of this just after I sent the reply, but you should be
able to set the attribute to 'undef', ie:

   $url->scheme(undef)
   $a = url->scheme;

This might do the job:

 sub scheme {
    my $this = shift;
    my($oldscheme) = $this->{'scheme'};
    $this->{'scheme'} = shift if (@_);
    return($oldscheme);
 }

--Gisle