[ic] Newbie: constructing Perl subroutines that use CPAN and other external modules

Ethan Rowe ethan at endpoint.com
Sat Jul 9 12:45:56 EDT 2005

Jeff Boes wrote:

>Can someone point me to examples of constructing Perl functions (either
>global subs, catalog subs, whatever) which make use of CPAN or other
>external modules? For example, I'm trying to use Date::Manip:
>sub foo {
>  ...
>  &Date::Manip::Date_Init();
>  ...
>I have a "require Date::Manip" directive in my interchange.cfg file, I
>have a "use Date::Manip;" inside the function body. The function gets
>called at the appropriate time, and I get this error:
>>Safe: Can't locate object method "new" via package "IO::File" (perhaps you forgot to load "IO::File"?) at /usr/local/lib/perl5/site_perl/5.8.3/Date/Manip.pm line 5345.
>I added a "require IO::File" directive, and a "use IO::File;" to the
>function, but without success. When an external module is loaded at
>configuration time, is there some restriction on what additional
>external modules it can use?

Access to outside modules and such is limited, depending on the 
context.  If you're writing a catalog-level sub, usertag, etc., then 
you're limited by the Safe module -- everything in this context runs 
under Safe, and thus only has a limited number of objects available and 
no ability to use external modules.

If you want to use the Date::Manip module, you need a global-level 
routine, be it a globalsub, actionmap, usertag, or filter.  By 
global-level, you define them at the interchange level rather than the 
catalog.  It could be an include or the actual code definition right in 
your <IC_ROOT>/interchange.cfg file.

My understanding of putting require directives in your interchange.cfg 
file is that it will try to make sure that the module is available when 
the Interchange daemon starts, but it doesn't mean much beyond that -- 
you would still need to implement your code in the manner described 
above.  I've not looked into this specifically, however, so perhaps 
someone will post a correction to this assertion.

- Ethan

Ethan Rowe
End Point Corporation
ethan at endpoint.com

More information about the interchange-users mailing list