<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Testing Perl Code - Suppressing Warnings</title>
	<link>http://blog.meesqa.com/2008/04/30/testing-perl-code-suppressing-warnings/</link>
	<description>Michael E. Ensminger's thoughts on software development, testing and quality assurance</description>
	<pubDate>Wed, 08 Feb 2012 21:54:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: Markus</title>
		<link>http://blog.meesqa.com/2008/04/30/testing-perl-code-suppressing-warnings/#comment-32140</link>
		<author>Markus</author>
		<pubDate>Fri, 06 Aug 2010 11:55:56 +0000</pubDate>
		<guid>http://blog.meesqa.com/2008/04/30/testing-perl-code-suppressing-warnings/#comment-32140</guid>
		<description>Thanks! Just what I was looking for. Cooked up a uitility method if anyone is interested.

# Executes the supplied code returning a hashref:
# 'warnings' =&#62; arrayref of any warning messages 
# 'warning'  =&#62; most recent warning message
# 'result'   =&#62; executed code result
#
# my $run = trap_warn( sub { warn 'tjoho!'; return 2 } );
#
# print $run-&#62;{'warnings'}[0]; # 'tjoho!'
# print $run-&#62;{'warning'};     # 'tjoho!'
# print $run-&#62;{'result'};      # 2
my $DIAG_TRAPPED_WARNS = 0;

sub trap_warn {
    my $code = shift;

    my @warn_message = ();
    local $SIG{__WARN__} = sub {
        push @warn_message, shift;
        diag "Trapped warn: ".$warn_message[-1] if $DIAG_TRAPPED_WARNS;
    };

    my $result =  # Run code

    return { 'warnings' =&#62; \@warn_message,
             'warning'  =&#62; pop @warn_message,
             'result'   =&#62; $result };
}</description>
		<content:encoded><![CDATA[<p>Thanks! Just what I was looking for. Cooked up a uitility method if anyone is interested.</p>
<p># Executes the supplied code returning a hashref:<br />
# &#8216;warnings&#8217; =&gt; arrayref of any warning messages<br />
# &#8216;warning&#8217;  =&gt; most recent warning message<br />
# &#8216;result&#8217;   =&gt; executed code result<br />
#<br />
# my $run = trap_warn( sub { warn &#8216;tjoho!&#8217;; return 2 } );<br />
#<br />
# print $run-&gt;{&#8217;warnings&#8217;}[0]; # &#8216;tjoho!&#8217;<br />
# print $run-&gt;{&#8217;warning&#8217;};     # &#8216;tjoho!&#8217;<br />
# print $run-&gt;{&#8217;result&#8217;};      # 2<br />
my $DIAG_TRAPPED_WARNS = 0;</p>
<p>sub trap_warn {<br />
    my $code = shift;</p>
<p>    my @warn_message = ();<br />
    local $SIG{__WARN__} = sub {<br />
        push @warn_message, shift;<br />
        diag &#8220;Trapped warn: &#8220;.$warn_message[-1] if $DIAG_TRAPPED_WARNS;<br />
    };</p>
<p>    my $result =  # Run code</p>
<p>    return { &#8216;warnings&#8217; =&gt; \@warn_message,<br />
             &#8216;warning&#8217;  =&gt; pop @warn_message,<br />
             &#8216;result&#8217;   =&gt; $result };<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chandrashekhar</title>
		<link>http://blog.meesqa.com/2008/04/30/testing-perl-code-suppressing-warnings/#comment-3571</link>
		<author>chandrashekhar</author>
		<pubDate>Tue, 09 Sep 2008 13:04:49 +0000</pubDate>
		<guid>http://blog.meesqa.com/2008/04/30/testing-perl-code-suppressing-warnings/#comment-3571</guid>
		<description>hi, 
i m new to testing, i would like to know hw to test already developed code in perl</description>
		<content:encoded><![CDATA[<p>hi,<br />
i m new to testing, i would like to know hw to test already developed code in perl</p>
]]></content:encoded>
	</item>
</channel>
</rss>

