Looks like not the OP's (i.e. davidfilmer) case, but, sadly, libtiff shipped with Strawberry Perl generates warnings as ugly pop-up GUI modal boxes, requiring user interaction to dispose. Therefore, without recompilation, the solution with Capture::Tiny won't work.
On the other hand, libtiff provides a TIFFSetWarningHandler function just for customizing error reporting. It is not exposed by the Perl wrapper, but adding that feature shouldn't be too difficult.
Ah, then I can do it:
use strict;
use warnings;
use Graphics::TIFF;
my $fn = 'TIFF01.TIF'; # a file known to generate
# a warning (as shown below)
DummyTiffLogger::init();
Graphics::TIFF-> Open( $fn, 'r' )
for 1..5;
package DummyTiffLogger {
sub logMessage {
my $s = shift;
printf "message logged: <%s>\n", $s
}
use Inline C => Config => LIBS => '-ltiff';
use Inline C => <<'END_OF_C';
#define BUFSIZE 1024
void _log(char* m, char* fmt, va_list ap) {
char* buf;
int len;
SV* sv;
Newxz(buf, BUFSIZE, char);
len = vsprintf(buf, fmt, ap);
Renew(buf, len + 1, char);
sv = newSV(0);
sv_usepvn_flags(sv, buf, len, SV_SMAGIC | SV_HAS_TRAILING_NUL);
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(sv));
PUTBACK;
call_pv("DummyTiffLogger::logMessage", G_DISCARD);
FREETMPS;
LEAVE;
}
void init() { TIFFSetWarningHandler(&_log); }
END_OF_C
} # package
__END__
message logged: <Unknown field with tag 32781 (0x800d) encountered>
message logged: <Unknown field with tag 32781 (0x800d) encountered>
message logged: <Unknown field with tag 32781 (0x800d) encountered>
message logged: <Unknown field with tag 32781 (0x800d) encountered>
message logged: <Unknown field with tag 32781 (0x800d) encountered>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.