bypass new() in _hsv_dot and switch to blessed() to avoid calling our own ref()
[scpubgit/HTML-String.git] / lib / HTML / String / Value.pm
index 1e75271..1eedc5e 100644 (file)
@@ -3,6 +3,7 @@ package HTML::String::Value;
 use strictures 1;
 use UNIVERSAL::ref;
 use Safe::Isa;
+use Scalar::Util qw(blessed);
 use Data::Munge;
 
 use overload
@@ -14,7 +15,10 @@ use overload
 ;
 
 sub new {
-    if (ref($_[0])) { my $c = shift; return $c->_hsv_unescaped_string->new(@_) }
+    if (blessed($_[0])) {
+        my $c = shift;
+        return $c->_hsv_unescaped_string->new(@_);
+    }
     my ($class, @raw_parts) = @_;
 
     my $opts = (ref($raw_parts[-1]) eq 'HASH') ? pop(@raw_parts) : {};
@@ -56,6 +60,7 @@ sub _hsv_escaped_string {
                 s/</&lt;/g;
                 s/>/&gt;/g;
                 s/"/&quot;/g;
+                s/'/&#39;/g;
               } $_->[0]
             : $_->[0]
     ), @{$self->{parts}};
@@ -86,7 +91,7 @@ sub _hsv_dot {
         push @parts, @new_parts;
     }
 
-    return ref($self)->new(@parts, { ignore => $self->{ignore} });
+    return bless({ %$self, parts => \@parts }, blessed($self));
 }
 
 sub _hsv_is_true {
@@ -94,10 +99,17 @@ sub _hsv_is_true {
     return 1 if grep $_, map $_->[0], @{$self->{parts}};
 }
 
+# we need to local $@ here because some modules (cough, TT, cough)
+# will do a 'die $@ if $@' without realising that it wasn't their eval
+# that set it
+
 sub isa {
     my $self = shift;
     return (
-        eval { $self->_hsv_unescaped_string->isa(@_) }
+        do {
+            local $@;
+            eval { blessed($self) and $self->_hsv_unescaped_string->isa(@_) }
+        }
         or $self->SUPER::isa(@_)
     );
 }
@@ -105,7 +117,10 @@ sub isa {
 sub can {
     my $self = shift;
     return (
-        eval { $self->_hsv_unescaped_string->can(@_) }
+        do {
+            local $@;
+            eval { blessed($self) and $self->_hsv_unescaped_string->isa(@_) }
+        }
         or $self->SUPER::can(@_)
     );
 }
@@ -153,7 +168,7 @@ Each entry in @parts consists of one of:
 
   [ 'some text that will not be escaped', 0 ]
 
-  [ 'text that you DO want to be scaped', 1 ]
+  [ 'text that you DO want to be escaped', 1 ]
 
   $existing_html_string_value