Hi,

I'm trying to find a good way for CAD::Drawing::IO to determine which of the 
CAD::Drawing::IO::* modules are available.

Basically, there are save() and load() functions in IO.pm which allow an 
explicit "type" argument or the type can be derived from the file extension.

Right now, the beginning of IO.pm is just like:

  use CAD::Drawing::IO::OpenDWG;
  use CAD::Drawing::IO::PostScript;
  use CAD::Drawing::IO::Image;
  use CAD::Drawing::IO::PgDB;
  use CAD::Drawing::IO::Circ;
  use CAD::Drawing::IO::Tk;

  our @ISA = qw(
    CAD::Drawing::IO::OpenDWG
    CAD::Drawing::IO::PostScript
    CAD::Drawing::IO::Image
    CAD::Drawing::IO::PgDB
    CAD::Drawing::IO::Circ
    CAD::Drawing::IO::Tk
    );

The main reason that I'd like to be able to make each module optional is that 
OpenDWG.pm requires DWGI.pm (a wrapper on a non-gpl toolkit which I cannot 
distribute with the module.)

>From looking at DBI.pm, available drivers are found by searching @INC when 
connect() is called, and then there is a require().  I don't think that I 
need anything as elaborate as the DBI setup, and I'd rather that this just be 
done at compile time (plus, searching @INC seems like a waste and IO.pm needs 
to know which save_<type>() and load_<type>() functions are available in 
order to redirect to the backend.)

Since adding a backend requires changes to IO.pm, maybe it should just be part 
of the IO.pm install procedure?  Or, I could look at entirely removing the 
type determination and redirects from IO.pm (allowing the backends to 
"install" themselves (and then looping through the list of available 
backends, calling an is_this_yours() function to allow the implicit filetype 
determination to come from the backend itself?)), but I'm not sure how to go 
about that.

Currently, the redirection is like so:
  # (stripped from the middle of a longer function in IO.pm)
  elsif($type eq "postscript") {
    ($action eq "save") && return($self->saveps($filename, $opt));
    ($action eq "load") && return($self->loadps($filename, $opt));
  }
  elsif($type eq "image") {
    ($action eq "save") && return($self->saveimg($filename, $opt) );
    ($action eq "load") && return($self->loadimg($filename, $opt) );
  }


Thanks in advance for any suggestions,
Eric

Reply via email to