Browse files

Protect against unknown core data types that don't implement "can", e…

…g VSTRING
  • Loading branch information...
1 parent baf9df7 commit a2a199ae1553cb5f4b8479a998e607d01ac1ab39 @iarna committed Jul 5, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/Data/Printer.pm
  2. +23 −0 t/34-vstrings.t
View
2 lib/Data/Printer.pm
@@ -606,7 +606,7 @@ sub _class {
my $ref = ref $item;
# if the user specified a method to use instead, we do that
- if ( $p->{class_method} and my $method = $item->can($p->{class_method}) ) {
+ if ( $p->{class_method} and Scalar::Util::blessed($item) and my $method = $item->can($p->{class_method}) ) {
return $method->($item, $p);
}
View
23 t/34-vstrings.t
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+BEGIN {
+ $ENV{ANSI_COLORS_DISABLED} = 1;
+ delete $ENV{DATAPRINTERRC};
+ use File::HomeDir::Test; # avoid user's .dataprinter
+
+ use Test::More;
+ use Data::Printer;
+
+}
+
+my $scalar = v1.2.3;
+eval {
+ like( p($scalar), qr/^VSTRING/, "VSTRINGs" );
+};
+if ($@) {
+ fail( "VSTRINGs" );
+ diag( $@ );
+}
+
+done_testing();

0 comments on commit a2a199a

Please sign in to comment.