in reply to can't seem to import properly when using require

What could I be missing?

A BEGIN{} block

As in

BEGIN { eval { require Term::ANSIColor ; 1; } and do { Term::ANSIColor ->import( ); Term::ANSIColor ->import( qw/:constants / ); }; }

See also Re: Best way to dynamically use a .pm?

Replies are listed 'Best First'.
Re^2: can't seem to import properly when using require
by ttlgreen (Sexton) on Feb 26, 2012 at 23:35 UTC

    Perfect! Thanks!

      I see you have yet to test in an environment where Term::ANSIColor isn't installed.

      You also didn't actually show any of the code where the errors actually happen.

      You can't conditionally use compile-time magic unless you also only conditionally compile the magic-using code.

      So, I usually drop the BEGIN block and fix my code so it does not depend on compile-time magic from the optional module. But, looking at the docs for Term::ANSIColor, it looks like it flings compile-time magic all over the place. So you might find it easier to conditionally compile any code that makes use of said magic.

      Not that I will help with that since you didn't include any of said magic-using code (that was failing).

      - tye