[Dancer-users] why does "warn" fail?

Brian E. Lozier brian at massassi.com
Sun Jan 23 09:08:16 CET 2011


$VERSION   = '1.2003';

Looks like I'm using 1.2003.

Thanks for your detailed reply, I appreciate it.

On Sat, Jan 22, 2011 at 12:53 PM, Flavio Poletti <polettix at gmail.com> wrote:
> Hi,
>    there are different topics involved here.
> The first one regards the version of Dancer you're running. I tried to start
> a sample application with "dancer -a Whatever" and added a warn call in the
> only route handler, but did not get your error. I ran my example with Dancer
> 1.2002 and the result was the error I expected, which leads us to the
> following point.
> The second topic deals with warnings promoted to fatal errors. This is
> triggered by the "warnings" setting, whose documentation is in
> Dancer::Config. This setting is enabled by default in the "development"
> environment, so you should turn this off to get rid of the errors. From what
> I understood, this is meant to be a useful feature to ensure that you don't
> get warnings from modules, etc. which you might want to catch as soon as
> you're in the development process.
> About your muscle memory, if you want to use "warn" instead of "warning" I
> think that your best option is to propose a patch which I suppose could be
> developed along the following lines:
> * read how to contribute to the project
> in https://github.com/sukria/Dancer/blob/devel/lib/Dancer/Development.pod
> * add a configuration option "warn_as_warning" in lib/Dancer/Config.pm
> * use this configuration option in lib/Dancer/Route.pm subroutine "execute"
> like this:
> # -------------------------------------
>  sub execute {
>      my ($self) = @_;
>
> -    if (Dancer::Config::setting('warnings')) {
> +    if (Dancer::Config::setting('warn_as_warning')) {
> +      local $SIG{__WARN__} = \&Dancer::Logger::warning;
> +      return $self->code->();
> +    }
> +    elsif (Dancer::Config::setting('warnings')) {
>          my $warning;
>          local $SIG{__WARN__} = sub { $warning = $_[0] };
>          my $content = $self->code->();
> # -------------------------------------
> * write tests
> Anyway, separating how you send warnings in your web application from how
> you (or others) do that in the modules you use might be very useful to
> detect problems early... a good reason to teach something new to your muscle
> memory!
> Cheers,
>     Flavio.
>
>
>
> On Sat, Jan 22, 2011 at 2:08 AM, Brian E. Lozier <brian at massassi.com> wrote:
>>
>> As a perl veteran I am used to using the built-in "warn" function to
>> write to STDERR.  Under mod_perl/Apache this prints to the web
>> server's error log.  Using my dancer app like this:
>>
>> plackup -L Shotgun app.pl
>>
>> If I have a "warn" anywhere in my app, I get an error message:
>>
>> Error trace
>>
>> status code needs to be an integer greater than or equal to 100 at
>> /usr/local/lib/perl5/site_perl/5.12.2/Plack/Middleware/StackTrace.pm
>> line 27
>>
>> However, if I print STDERR "msg"; that works.  My question is: what
>> happened to warn?  Can it be fixed so that it writes to STDERR instead
>> of triggering an error message?
>>
>> I know about the "warning" function but it's really hard to change 10
>> years of muscle memory!
>>
>> Thanks,
>> Brian
>> _______________________________________________
>> Dancer-users mailing list
>> Dancer-users at perldancer.org
>> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
>


More information about the Dancer-users mailing list