diff --git a/Makefile.PL b/Makefile.PL index 9c8f66f..38e0250 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -15,6 +15,7 @@ perl_version '5.008'; requires 'Digest::MD5' => undef; requires 'Text::Balanced' => undef; requires 'Encode' => undef; +requires 'Scalar::Util' => undef; test_requires 'Test::More' => '0.42'; test_requires 'Test::Exception' => undef; test_requires 'List::MoreUtils' => undef; diff --git a/lib/Text/Markdown.pm b/lib/Text/Markdown.pm index 1c1f93e..7bb4fd6 100644 --- a/lib/Text/Markdown.pm +++ b/lib/Text/Markdown.pm @@ -7,6 +7,7 @@ use re 'eval'; use Digest::MD5 qw(md5_hex); use Encode qw(); use Carp qw(croak); +use Scalar::Util qw(blessed); use base 'Exporter'; our $VERSION = '1.000031'; # 1.0.31 @@ -186,7 +187,7 @@ sub markdown { my ( $self, $text, $options ) = @_; # Detect functional mode, and create an instance for this run - unless (ref $self) { + unless (blessed($self) && $self->isa('Text::Markdown')) { if ( $self ne __PACKAGE__ ) { my $ob = __PACKAGE__->new(); # $self is text, $text is options diff --git a/t/50blessed-string.t b/t/50blessed-string.t new file mode 100644 index 0000000..21a6365 --- /dev/null +++ b/t/50blessed-string.t @@ -0,0 +1,26 @@ +use strict; +use warnings; +use utf8; +use Test::More; +use Text::Markdown qw(markdown); + +plan tests => 1; + +{ + # emulate class like Text::Xslate::Type::Raw + package # + StringClass; + + use overload ( + q{""} => sub { ${ $_[0] } }, + fallback => 1, + ); + sub new { + my ($class, $str) = @_; + bless \$str, $class; + } +} + +my $src = StringClass->new('foo'); +is(markdown($src), "

foo

\n"); +