[Mapserver-users] Problems with PerlMapscript 3.7 Syntax

Slaven Rezic slaven at rezic.de
Thu May 1 12:45:07 PDT 2003


Sean Gillies <sgillies at frii.com> writes:

> I can't speak for the developer who committed the change, but
> it appears to me that the developer wants to promote some
> degree of uniformity across object methods.  The mapObj has a
> save() method that outputs to disk, and it seems natural that
> the extension to imageObj that outputs to disk should also be
> named 'save'.
> 
> Is not at all productive?  If all mapping objects had a save()
> method, one could reliably save an arbitrary object without
> having to do any type checking, or looking up whether you have
> to use 'saveMap' or 'saveImage' or 'saveSymbol'.  Objects
> save themselves using methods uniformly named 'save'.  This
> promotes development of more modular and reusable code.  To me,
> that is productive.
> 
> I don't deny that refactoring scripts to work with the newer
> MapScript module will have a cost.  One way to enable a script
> to work with 3.6 mapscript and 4.0 mapscript is to use
> try/catch.  This example in Python:
> 
> try:
> 	img.saveImage('foo.png')
> except AttributeError:
> 	img.save('foo.png')
> 
> With Perl it's a bit uglier since you have to eval() and trap
> errors, but it's the same idea.
> 

I have to disagree. It's not ugly, it's maybe named somewhat strange
for non-perlers:

eval {
    $img->saveImage("foo.png");
}; if ($@) {
    $img->save("foo.png");
}

But you should better either use ->can:

    $image_save = $img->can("save") || $img->can("saveImage");
    $img->save("foo.png");

or create a compatibility method:

    if (!defined &mapscript::imageObj::saveImage) {
        *mapscript::imageObj::saveImage = \&mapscript::imageObj::save;
    }

Such a module with compatibility methods could even go into the
standard mapserver distribution.

Regards,
	Slaven

-- 
Slaven Rezic - slaven at rezic.de
  BBBike - route planner for cyclists in Berlin
  WWW version:                           http://www.bbbike.de
  Perl/Tk version for Unix and Windows:  http://bbbike.sourceforge.net



More information about the MapServer-users mailing list