drop perl requirement to 5.8
Dan Book [Sat, 7 Nov 2015 04:55:44 +0000 (23:55 -0500)]
.travis.yml
Build.PL
META.json
cpanfile
lib/DOM/Tiny.pm
lib/DOM/Tiny/CSS.pm
lib/DOM/Tiny/Collection.pm
lib/DOM/Tiny/Entities.pm
lib/DOM/Tiny/HTML.pm
t/dom.t

index a598abc..ed5c2e7 100644 (file)
@@ -6,3 +6,4 @@ perl:
   - "5.14"
   - "5.12"
   - "5.10"
+  - "5.8"
index 237996a..c4f71f7 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -17,7 +17,7 @@ if (not @missing)
     use strict;
     use warnings;
 
-    use 5.010001;
+    use 5.008001;
     # use Module::Build::Tiny 0.034;
     Module::Build::Tiny::Build_PL();
 }
@@ -61,7 +61,7 @@ EOW
     }
 
 
-    # This section was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.040.
+    # This section was automatically generated by Dist::Zilla::Plugin::ModuleBuild v5.041.
     use strict;
     use warnings;
 
@@ -87,9 +87,10 @@ EOW
         "Exporter" => 0,
         "List::Util" => 0,
         "Scalar::Util" => 0,
-        "perl" => "5.010001"
+        "perl" => "5.008001"
       },
       "test_requires" => {
+        "Encode" => 0,
         "JSON::Tiny" => "0.41",
         "Test::More" => "0.88"
       }
@@ -97,6 +98,7 @@ EOW
 
 
     my %fallback_build_requires = (
+      "Encode" => 0,
       "JSON::Tiny" => "0.41",
       "Test::More" => "0.88"
     );
index 4b7d925..aee8400 100644 (file)
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Dan Book <dbook@cpan.org>"
    ],
    "dynamic_config" : 0,
-   "generated_by" : "Dist::Zilla version 5.040, CPAN::Meta::Converter version 2.150005",
+   "generated_by" : "Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005",
    "license" : [
       "artistic_2"
    ],
             "Exporter" : "0",
             "List::Util" : "0",
             "Scalar::Util" : "0",
-            "perl" : "5.010001"
+            "perl" : "5.008001"
          }
       },
       "test" : {
          "requires" : {
+            "Encode" : "0",
             "JSON::Tiny" : "0.41",
             "Test::More" : "0.88"
          }
index 1a7e6f4..ae29cc4 100644 (file)
--- a/cpanfile
+++ b/cpanfile
@@ -1,8 +1,9 @@
-requires 'perl' => '5.010001';
+requires 'perl' => '5.008001';
 requires 'Carp';
 requires 'Class::Tiny::Chained';
 requires 'Exporter';
 requires 'List::Util';
 requires 'Scalar::Util';
+test_requires 'Encode';
 test_requires 'JSON::Tiny' => '0.41';
 test_requires 'Test::More' => '0.88';
index 247855f..84dfeea 100644 (file)
@@ -164,8 +164,10 @@ sub type { shift->tree->[0] }
 sub val {
   my $self = shift;
 
+  my $tag = $self->tag;
+
   # "option"
-  return $self->{value} // $self->text if (my $tag = $self->tag) eq 'option';
+  return defined $self->{value} ? $self->{value} : $self->text if $tag eq 'option';
 
   # "textarea", "input" or "button"
   return $tag eq 'textarea' ? $self->text : $self->{value} if $tag ne 'select';
@@ -284,8 +286,8 @@ sub _parent { $_[0]->tree->[$_[0]->type eq 'tag' ? 3 : 2] }
 sub _parse { DOM::Tiny::HTML->new(xml => shift->xml)->parse(shift)->tree }
 
 sub _replace {
-  my ($self, $parent, $tree, @nodes) = @_;
-  splice @$parent, _offset($parent, $tree), 1, _link($parent, @nodes);
+  my ($self, $parent, $child, @nodes) = @_;
+  splice @$parent, _offset($parent, $child), 1, _link($parent, @nodes);
   return $self->parent;
 }
 
index dbe552a..a694186 100644 (file)
@@ -98,7 +98,9 @@ sub _compile {
 
     # Attributes
     elsif ($css =~ /\G$ATTR_RE/gco) {
-      push @$last, ['attr', _name($1), _value($2 // '', $3 // $4 // $5, $6)];
+      my $op = defined $2 ? $2 : '';
+      my $value = defined $3 ? $3 : (defined $4 ? $4 : $5);
+      push @$last, ['attr', _name($1), _value($op, $value, $6)];
     }
 
     # Pseudo-class (":not" contains more selectors)
@@ -133,7 +135,7 @@ sub _equation {
   return $num if $equation !~ /(?:(-?(?:\d+)?)?(n))?\s*\+?\s*(-?\s*\d+)?\s*$/i;
   $num->[0] = defined($1) && $1 ne '' ? $1 : $2 ? 1 : 0;
   $num->[0] = -1 if $num->[0] eq '-';
-  $num->[1] = $3 // 0;
+  $num->[1] = $3 || 0;
   $num->[1] =~ s/\s+//g;
   return $num;
 }
index 857a92b..0a41eb5 100644 (file)
@@ -7,6 +7,8 @@ use Exporter 'import';
 use List::Util;
 use Scalar::Util 'blessed';
 
+our $VERSION = '0.001';
+
 our @EXPORT_OK = ('c');
 
 sub TO_JSON { [@{shift()}] }
@@ -42,7 +44,7 @@ sub grep {
 }
 
 sub join {
-  join $_[1] // '', map {"$_"} @{$_[0]};
+  join +(defined $_[1] ? $_[1] : ''), map {"$_"} @{$_[0]};
 }
 
 sub last { shift->[-1] }
index 54208f6..c3a32f8 100644 (file)
@@ -2,9 +2,10 @@ package DOM::Tiny::Entities;
 
 use strict;
 use warnings;
-use utf8;
 use Exporter 'import';
 
+our $VERSION = '0.001';
+
 our @EXPORT_OK = qw(html_unescape xml_escape);
 
 # To generate a new HTML entity table run this command
index fc84d09..48a89e0 100644 (file)
@@ -6,8 +6,10 @@ use DOM::Tiny::Entities qw(html_unescape xml_escape);
 use Scalar::Util 'weaken';
 use Class::Tiny::Chained 'xml', { tree => sub { ['root'] } };
 
+our $VERSION = '0.001';
+
 my $ATTR_RE = qr/
-  ([^<>=\s\/]+|\/)                    # Key
+  ([^<>=\s\/]+|\/)                     # Key
   (?:
     \s*=\s*
     (?s:(["'])(.*?)\g{-2}|([^>\s]*))   # Value
@@ -119,7 +121,7 @@ sub parse {
         # Attributes
         my (%attrs, $closing);
         while ($attr =~ /$ATTR_RE/go) {
-          my ($key, $value) = ($xml ? $1 : lc $1, $3 // $4);
+          my ($key, $value) = ($xml ? $1 : lc $1, defined $3 ? $3 : $4);
 
           # Empty tag
           ++$closing and next if $key eq '/';
diff --git a/t/dom.t b/t/dom.t
index ed69234..d80a3c3 100644 (file)
--- a/t/dom.t
+++ b/t/dom.t
@@ -774,9 +774,12 @@ is $dom->at('[test=""]')->tag,  'div', 'right tag';
 is $dom->at('[test2=""]')->tag, 'div', 'right tag';
 is $dom->at('[test3=""]'), undef, 'no result';
 
-# Multi-line in attribute
-$dom = DOM::Tiny->new(qq{<div test="line1\nline2" />});
-is $dom->at('div')->attr->{test}, "line1\nline2", 'multi-line attribute';
+# Multi-line attribute
+$dom = DOM::Tiny->new(qq{<div class="line1\nline2" />});
+is $dom->at('div')->attr->{class}, "line1\nline2", 'multi-line attribute value';
+is $dom->at('.line1')->tag, 'div', 'right tag';
+is $dom->at('.line2')->tag, 'div', 'right tag';
+is $dom->at('.line3'), undef, 'no result';
 
 # Whitespaces before closing bracket
 $dom = DOM::Tiny->new('<div >content</div>');