rename sanitize to to_xml_string, add to_html_string
Matt S Trout [Thu, 22 Oct 2009 14:46:42 +0000 (10:46 -0400)]
lib/HTML/Tags.pm
lib/XML/Tags.pm
t/tags.t

index 6957831..de71d2c 100644 (file)
@@ -27,4 +27,6 @@ sub import {
   XML::Tags->import($opts, @HTML_TAGS, @rest);
 }
 
+sub to_html_string { XML::Tags::to_xml_string(@_) }
+
 1;
index 40f6926..2637df7 100644 (file)
@@ -19,7 +19,7 @@ sub import {
   $IN_SCOPE = 1;
 }
 
-sub sanitize {
+sub to_xml_string {
   map { # string == text -> HTML, scalarref == raw HTML, other == passthrough
     ref($_)
       ? (ref $_ eq 'SCALAR' ? $$_ : $_)
@@ -40,13 +40,14 @@ sub _find_target {
 
 sub _set_glob {
   # stupid insanity. delete anything already there so we disassociated
-  # the *CORE::GLOBAL::glob typeglob. Then the compilation of the eval
+  # the *CORE::GLOBAL::glob typeglob. Then the string reference call
   # revivifies it - i.e. creates us a new glob, which we get a reference
   # to, which we can then assign to.
-  # doing it without the eval doesn't - it binds to the version in scope
+  # doing it without the quotes doesn't - it binds to the version in scope
   # at compile time, which means after a delete you get a nice warm segv.
   delete ${CORE::GLOBAL::}{glob};
-  *{eval '\*CORE::GLOBAL::glob'} = $_[0];
+  no strict 'refs';
+  *{'CORE::GLOBAL::glob'} = $_[0];
 }
 
 sub _export_tags_into {
index c58e7e5..9979e7f 100644 (file)
--- a/t/tags.t
+++ b/t/tags.t
@@ -31,7 +31,7 @@ use Test::More qw(no_plan);
 }
 
 is(
-  join(', ', XML::Tags::sanitize Foo::foo()),
+  join(', ', XML::Tags::to_xml_string Foo::foo()),
   '<one>, <two>, <three>',
   'open tags ok'
 );
@@ -39,13 +39,13 @@ is(
 ok(!eval { Foo::bar(); 1 }, 'Death on use of unimported tag');
 
 is(
-  join(', ', XML::Tags::sanitize Foo::baz()),
+  join(', ', XML::Tags::to_xml_string Foo::baz()),
   '</bar>',
   'close tag ok'
 );
 
 is(
-  join('', XML::Tags::sanitize Foo::quux),
+  join('', HTML::Tags::to_html_string Foo::quux),
   '<html><body id="spoon">YAY</body></html>',
   'HTML tags ok'
 );