in reply to Re: Taint error in Printer module
in thread Taint error in Printer module

For clarification, the Printer module code I posted is from Printer::Unix.pm (the file mentioned in the error message received), not Printer.pm.

Where do you suggest I add the code? To MY code? To Printer::Unix.pm or Printer.pm? I'm currently resetting $ENV{PATH} in all 3 files and still getting the taint error.

Replies are listed 'Best First'.
Re^3: Taint error in Printer module
by kcott (Archbishop) on Aug 09, 2017 at 08:05 UTC

    OK, I can see how that might have been confusing. The module is Printer::Unix. It's bundled with Printer, rather than being provided as a separately distributed module. You can find it as follows:

    • At the top of the Printer page, you'll see a link to the distribution page: Printer-0.98.
    • That page has a number of links. Against the heading Special Files, you'll see a link to MANIFEST.
    • On the MANIFEST page, you'll see links to all the items that make up the distribution; lib/Printer/Unix.pm links to the source code for Printer::Unix.

    There's probably additional confusion because the source code for Printer has

    require Printer::Unix;

    but the source code for Printer::Unix has no package statement. The module is Printer::Unix but its namespace is Printer.

    The code I suggested should be added to your program as I originally stated: nothing has changed in that respect.

    As a general rule, you should not make changes to module code you've installed from CPAN. If you have made any changes, you should reverse them: if in doubt, reinstall the module.

    You should be able to create a SSCCE fairly easily. Start with code similar to what I suggested; add use Printer;; then your sub printX {...}; then a call to exercise it (printX(@args)).

    Important: Note that I used printX. You don't have to call it that; but do not call it print: that's the name of a core function (print) and could easily cause problems.

    The Printer module only works with a limited number of platforms that I don't have available. I'd be happy to look at your SSCCE code but I'm not in a position to run and test it.

    You should also change your current indirect object syntax:

    my $prn=new Printer('linux' => '6L',);

    to

    my $prn = Printer::->new(linux => '6L');

    See Indirect Object Syntax for an explanation. Note the emboldened text: "... use of this syntax is discouraged ...".

    — Ken

      I'll go back and make the changes you suggested. I thought I used the exact syntax for Printer stated in the documentation.

      Here's the kicker, it's not always failing. Even though I'm explicitly setting ENV{PATH} in all 3 files, every 3 or so times the script runs, it somehow resets the ENV{PATH} to the original value. Only when I explicitly reset it right before it fails in Printer::Unix.pm does it get the correct ENV{PATH}.

      $ENV{PATH}='/usr/bin'; warn "path=$ENV{PATH}\n"; open PRINTER, "| $self->{print_command}->{linux}-{command}" or Carp::croak..
      ...And then it will again randomly fail (more like every 6th running instead of every 3rd), with the new error Can't open printer connection to lp -d 6L.

      ETA: However, if my code is:

      warn "path=$ENV{PATH}\n"; open PRINTER, "| $self->{print_command}->{linux}-{command}" or Carp::croak..
      (without the redundant 4th reset of ENV{PATH}), sometimes the warning output shows the correct PATH, sometimes, it doesn't.