p5-Text-Xslate icon indicating copy to clipboard operation
p5-Text-Xslate copied to clipboard

strange lack of warnings

Open forwardever opened this issue 14 years ago • 5 comments

the following code does not provide any warnings -> method call on undef value

is this expected behaviour?

use Text::Xslate;

my $tx = Text::Xslate->new();

my %vars = (
    title => 'A list of books',
    oo    => undef
);

# for strings
my $template = q{
    <: $title :>
    <: $oo.unknown_method :>

};

print $tx->render_string($template, \%vars);

forwardever avatar Nov 26 '11 15:11 forwardever

Yes, any operation on nil(undef) says nothing by default while <: $title.unknown_method :> complains warnings.

You can change this behavior by setting Text::Xslate->new( verbose => 2 ).

Should verbose => be set by default? What do you think of it?

gfx avatar Nov 27 '11 01:11 gfx

both type of warnings "Use of nil to print" and "Use of nil to invoke method foo" will be raised using verbose => 2

but while "Use of nil to print" is pretty common (I don't want to initialize all my values $value //= ""), calling methods on undef values just seem wrong and much less common

so both type of warnings might be activated on different levels? "Use of nil to print" => verbose 2 "Use of nil to invoke method foo" => verbose 1

forwardever avatar Nov 27 '11 12:11 forwardever

Sure. I will change the level of two warning types as:

  • default verbose level to 2
  • "Use of nil to print" to level 3
  • Some of warnings on nil to level 3

Thanks to the suggestion.

gfx avatar Nov 28 '11 00:11 gfx

thanks, hope this helps to make debugging a bit easier (as the old behavior produced some hard to find bugs at least in my use cases :)

forwardever avatar Nov 28 '11 23:11 forwardever

@gfx "Sure. I will change the level of two warning types as:"

Has it been changed?

lestrrat avatar Jul 22 '14 06:07 lestrrat