perl 5.8 support (mst)
Dan Book [Mon, 9 Nov 2015 19:03:00 +0000 (14:03 -0500)]
.travis.yml
Changes
META.json
Makefile.PL
README.pod
cpanfile
lib/DOM/Tiny.pm
lib/DOM/Tiny/_CSS.pm
lib/DOM/Tiny/_Collection.pm
lib/DOM/Tiny/_HTML.pm

index a598abc..ed5c2e7 100644 (file)
@@ -6,3 +6,4 @@ perl:
   - "5.14"
   - "5.12"
   - "5.10"
+  - "5.8"
diff --git a/Changes b/Changes
index 243df9f..e3b5174 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,4 +1,5 @@
 {{$NEXT}}
+  - Support perl 5.8 (mst)
 
 0.001     2015-11-09 02:56:35 EST
   - First release
index b64b357..30b084c 100644 (file)
--- a/META.json
+++ b/META.json
@@ -47,7 +47,7 @@
             "Exporter" : "0",
             "List::Util" : "0",
             "Scalar::Util" : "0",
-            "perl" : "5.010001"
+            "perl" : "5.008001"
          }
       },
       "test" : {
index 8f37530..4df3382 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use 5.010001;
+use 5.008001;
 
 use ExtUtils::MakeMaker;
 
@@ -14,7 +14,7 @@ my %WriteMakefileArgs = (
   },
   "DISTNAME" => "DOM-Tiny",
   "LICENSE" => "artistic_2",
-  "MIN_PERL_VERSION" => "5.010001",
+  "MIN_PERL_VERSION" => "5.008001",
   "NAME" => "DOM::Tiny",
   "PREREQ_PM" => {
     "Carp" => 0,
index e8ee528..770409f 100644 (file)
@@ -1118,6 +1118,14 @@ Report any issues on the public bugtracker.
 
 Dan Book <dbook@cpan.org>
 
+=head1 CONTRIBUTORS
+
+=over
+
+=item Matt S Trout (mst)
+
+=back
+
 =head1 COPYRIGHT AND LICENSE
 
 This software is Copyright (c) 2015 by Dan Book.
index e1ffa35..581cd98 100644 (file)
--- a/cpanfile
+++ b/cpanfile
@@ -1,4 +1,4 @@
-requires 'perl' => '5.010001';
+requires 'perl' => '5.008001';
 requires 'Carp';
 requires 'Exporter';
 requires 'List::Util';
index 7a5e10a..77e4d91 100644 (file)
@@ -167,7 +167,8 @@ sub val {
   my $self = shift;
 
   # "option"
-  return $self->{value} // $self->text if (my $tag = $self->tag) eq 'option';
+  return defined($self->{value}) ? $self->{value} : $self->text
+    if (my $tag = $self->tag) eq 'option';
 
   # "textarea", "input" or "button"
   return $tag eq 'textarea' ? $self->text : $self->{value} if $tag ne 'select';
@@ -1505,6 +1506,14 @@ Report any issues on the public bugtracker.
 
 Dan Book <dbook@cpan.org>
 
+=head1 CONTRIBUTORS
+
+=over
+
+=item Matt S Trout (mst)
+
+=back
+
 =head1 COPYRIGHT AND LICENSE
 
 This software is Copyright (c) 2015 by Dan Book.
index 5ab9849..5ec2fe6 100644 (file)
@@ -109,7 +109,14 @@ sub _compile {
 
     # Attributes
     elsif ($css =~ /\G$ATTR_RE/gco) {
-      push @$last, ['attr', _name($1), _value($2 // '', $3 // $4 // $5, $6)];
+      push @$last, [
+        'attr', _name($1),
+        _value(
+          defined($2) ? $2 : '',
+          defined($3) ? $3 : defined($4) ? $4 : $5,
+          $6
+        ),
+      ];
     }
 
     # Pseudo-class (":not" contains more selectors)
@@ -144,7 +151,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] = defined($3) ? $3 : 0;
   $num->[1] =~ s/\s+//g;
   return $num;
 }
index eab6729..4c27742 100644 (file)
@@ -44,7 +44,7 @@ sub grep {
 }
 
 sub join {
-  join $_[1] // '', map {"$_"} @{$_[0]};
+  join +(defined($_[1]) ? $_[1] : ''), map {"$_"} @{$_[0]};
 }
 
 sub last { shift->[-1] }
index fb8c7f6..41c5ced 100644 (file)
@@ -8,10 +8,10 @@ use Scalar::Util 'weaken';
 our $VERSION = '0.002';
 
 my $ATTR_RE = qr/
-  ([^<>=\s\/]+|\/)                     # Key
+  ([^<>=\s\/]+|\/)                         # Key
   (?:
     \s*=\s*
-    (?s:(["'])(.*?)\g{-2}|([^>\s]*))   # Value
+    (?s:(?:"(.*?)")|(?:'(.*?)')|([^>\s]*)) # Value
   )?
   \s*
 /x;
@@ -33,7 +33,8 @@ my $TOKEN_RE = qr/
     |
       \?(.*?)\?                                       # Processing Instruction
     |
-      \s*([^<>\s]+\s*(?:(?:$ATTR_RE){0,32766})*+)     # Tag
+      \s*([^<>\s]+\s*(?>(?:$ATTR_RE){0,32766})*)       # Tag
+      # Workaround for perl's limit of * to {0,32767}
     )>
   |
     (<)                                               # Runaway "<"
@@ -46,13 +47,13 @@ my %RAW = map { $_ => 1 } qw(script style);
 # HTML elements that only contain raw text and entities
 my %RCDATA = map { $_ => 1 } qw(title textarea);
 
-# HTML elements with optional end tags
-my %END = (body => 'head', optgroup => 'optgroup', option => 'option');
-
-# HTML elements that break paragraphs
-map { $END{$_} = 'p' } (
-  qw(address article aside blockquote dir div dl fieldset footer form h1 h2),
-  qw(h3 h4 h5 h6 header hr main menu nav ol p pre section table ul)
+my %END = (
+  # HTML elements with optional end tags
+  body => 'head', optgroup => 'optgroup', option => 'option',
+  # HTML elements that break paragraphs
+  map +($_ => 'p'),
+    qw(address article aside blockquote dir div dl fieldset footer form h1 h2),
+    qw(h3 h4 h5 h6 header hr main menu nav ol p pre section table ul)
 );
 
 # HTML table elements with optional end tags
@@ -139,7 +140,8 @@ sub parse {
         # Attributes
         my (%attrs, $closing);
         while ($attr =~ /$ATTR_RE/go) {
-          my ($key, $value) = ($xml ? $1 : lc $1, $3 // $4);
+          my $key = $xml ? $1 : lc $1;
+          my $value = defined($2) ? $2 : defined($3) ? $3 : $4;
 
           # Empty tag
           ++$closing and next if $key eq '/';