> The following was supposedly scribed by
> darren chamberlain
> on Wednesday 21 January 2004 02:11 pm:

>* Eric Wilhelm <ewilhelm at sbcglobal.net> [2004/01/21 13:58]:
>> > The following was supposedly scribed by
>> > darren chamberlain
>> > on Wednesday 21 January 2004 11:10 am:
>
>"Supposedly"?  Aren't you verifying signatures?  ;)

:) no.  That's just the quote line.

>Well, if polymorphism isn't what you're after, couldn't you have
>CAD::Drawing::IO not define a load function, and have
>CAD::Drawing::IO::Foo declare package CAD::Drawing::IO and define a
>load?  Then, the user need simply do:
>
>  use CAD::Drawing::IO;
>  use CAD::Drawing::IO::OpenDWG;
>
>And calling load("file.dwg") uses the load defined in ::IO::OpenDWG?

But this still (essentially) leaves the user with hard-coded information about 
which format to use (making it impossible to do $drw->save($ARGV[0])).  My 
goal is to make all of the file formats (smile floormats) transparent in the 
hope that they eventually go away completely.

>Without any knowledge of the implementation, however, it sounds like
>what you want is polymorphism, and you're jumping through hoops to avoid
>using it.

What I'm going for is more like a big chain of elsif statements which is put 
together out of multiple packages.  If the user were to use an object from 
CAD::Drawing::IO::OpenDWG to call the save() function, that would be 
polymorphism.  I might be jumping through hoops at the module level, but I 
think this beats making the user jump through hoops at the main program 
level.

>> With this model, your main program would not have "use
>> CAD::Drawing::IO::IGES;", but simply "use CAD::Drawing;".
>
>This sounds exactly like DBI, which relies on DBDs being polymorphic.
>*shrug*

It is a lot like the DBI::connect() function, but load() does not return an 
object the way connect() does.  With DBI, once it gets hold of a classed 
object, DBI.pm is home-free and just has to return the blessed object, 
leaving the rest up to the polymorphism.  

My problem is more like DBI turned on its head.  e.g. with DBI::connect() you 
are at the beginning of the program and you get your $dbh which is used to 
call $dbh->select*foo() and such.

With CAD::Drawing, you get your $drw from CAD::Drawing->new() and from there 
you can either $drw->load("whatever.dwg|dxf") or just start adding entities 
to the drawing.  At the end (or the middle, or as many times as you like), 
you can $drw->save("file.ps") && $drw->save("file.dxf") && 
$drw->save("file.png", {size => [640,480]}) && $drw->save("file.dwg.gz").

Now, if I could just get the string "file.ps" to kindly bless itself into 
CAD::Drawing::IO::PostScript, I'd be in the free and clear;-)

Seriously, though.  That is basically what I'm trying to do.  Consider this, 
where you have a list of available packages in @found, and a $filename with 
(or without) an extension, and possibly an explicit $options{type} argument, 
and the following is part of the IO::save() function:

  foreach my $package (@found) {
    if(eval("\$" . $package . "::can_save(\$filename, \$options{type})") ) {
      my $r = eval($package . "::save_file(\$self, \$filename, \\%options)")
      return($r);
    }
  }

Thanks,
Eric

-- 
A counterintuitive sansevieria trifasciata was once literalized guiltily.
                                        --Product of Artificial Intelligence

Reply via email to