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

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:

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

Replies are listed 'Best First'.
Re^4: Taint error in Printer module
by ksublondie (Friar) on Aug 09, 2017 at 17:17 UTC
    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.