Merge remote branch 'koha-fbc/k_bug_5215' into master
[koha_fer] / misc / translator / TmplTokenizer.pm
index 9e1c762..838a59f 100644 (file)
@@ -1,6 +1,7 @@
 package TmplTokenizer;
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use TmplTokenType;
 use TmplToken;
 use VerboseWarnings qw( pedantic_p error_normal warn_normal warn_pedantic );
@@ -39,7 +40,7 @@ use vars qw( $pedantic_error_markup_in_pcdata_p );
 
 # Hideous stuff
 use vars qw( $re_directive $re_tmpl_var $re_tmpl_var_escaped $re_tmpl_include );
-use vars qw( $re_directive_control $re_tmpl_endif_endloop );
+use vars qw( $re_directive_control $re_tmpl_endif_endloop $re_xsl);
 BEGIN {
     # $re_directive must not do any backreferences
     $re_directive = q{<(?:(?i)(?:!--\s*)?\/?TMPL_(?:VAR|LOOP|INCLUDE|IF|ELSE|UNLESS)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))*\s*(?:--)?)>};
@@ -47,6 +48,7 @@ BEGIN {
     $re_tmpl_var = q{<(?:(?i)(?:!--\s*)?TMPL_(?:VAR)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))*\s*(?:--)?)>};
     $re_tmpl_include = q{<(?:(?i)(?:!--\s*)?TMPL_(?:INCLUDE)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))*\s*(?:--)?)>};
     # TMPL_VAR ESCAPE=1/HTML/URL
+    $re_xsl = q{<\/?(?:xsl:)(?:[\s\-a-zA-Z0-9"'\/\.\[\]\@\(\):=,$]+)\/?>};
     $re_tmpl_var_escaped = q{<(?:(?i)(?:!--\s*)?TMPL_(?:VAR|INCLUDE)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))\s+ESCAPE=(?:1|HTML|URL)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))*\s*(?:--)?)>};
     # Any control flow directive
     $re_directive_control = q{<(?:(?i)(?:!--\s*)?\/?TMPL_(?:LOOP|IF|ELSE|UNLESS)(?:\s+(?:[a-zA-Z][-a-zA-Z0-9]*=)?(?:'[^']*'|"[^"]*"|[^\s<>]+))*\s*(?:--)?)>};
@@ -98,22 +100,14 @@ sub JS_MODE_P              () {'js-mode-p'}        # cdata-mode-p must also be true
 sub ALLOW_CFORMAT_P    () {'allow-cformat-p'}
 
 sub new {
-    my $this = shift;
-    my($input) = @_;
-    my $class = ref($this) || $this;
-    my $self = {};
-    bless $self, $class;
-
-    my $handle = sprintf('TMPLTOKENIZER%d', $serial);
-    $serial += 1;
-
-    no strict;
-    open($handle, "<$input") || die "$input: $!\n";
-    use strict;
-    $self->{+FILENAME} = $input;
-    $self->{+HANDLE} = $handle;
-    $self->{+READAHEAD} = [];
-    return $self;
+    shift;
+    my ($filename) = @_;
+    open my $handle,$filename or die "can't open $filename";
+    bless {
+           filename => $filename
+           , handle => $handle
+           , readahead => []
+    } , __PACKAGE__;
 }
 
 ###############################################################################
@@ -122,12 +116,12 @@ sub new {
 
 sub filename {
     my $this = shift;
-    return $this->{+FILENAME};
+    return $this->{filename};
 }
 
 sub _handle {
     my $this = shift;
-    return $this->{+HANDLE};
+    return $this->{handle};
 }
 
 sub fatal_p {
@@ -142,12 +136,12 @@ sub syntaxerror_p {
 
 sub has_readahead_p {
     my $this = shift;
-    return @{$this->{+READAHEAD}};
+    return @{$this->{readahead}};
 }
 
 sub _peek_readahead {
     my $this = shift;
-    return $this->{+READAHEAD}->[$#{$this->{+READAHEAD}}];
+    return $this->{readahead}->[$#{$this->{readahead}}];
 }
 
 sub line_number_start {
@@ -201,24 +195,24 @@ sub _set_syntaxerror {
 
 sub _push_readahead {
     my $this = shift;
-    push @{$this->{+READAHEAD}}, $_[0];
+    push @{$this->{readahead}}, $_[0];
     return $this;
 }
 
 sub _pop_readahead {
     my $this = shift;
-    return pop @{$this->{+READAHEAD}};
+    return pop @{$this->{readahead}};
 }
 
 sub _append_readahead {
     my $this = shift;
-    $this->{+READAHEAD}->[$#{$this->{+READAHEAD}}] .= $_[0];
+    $this->{readahead}->[$#{$this->{readahead}}] .= $_[0];
     return $this;
 }
 
 sub _set_readahead {
     my $this = shift;
-    $this->{+READAHEAD}->[$#{$this->{+READAHEAD}}] = $_[0];
+    $this->{readahead}->[$#{$this->{readahead}}] = $_[0];
     return $this;
 }
 
@@ -883,7 +877,7 @@ sub next_token {
 
 sub blank_p ($) {
     my($s) = @_;
-    return $s =~ /^(?:\s|\&nbsp$re_end_entity|$re_tmpl_var)*$/os;
+    return $s =~ /^(?:\s|\&nbsp$re_end_entity|$re_tmpl_var|$re_xsl)*$/os;
 }
 
 sub trim ($) {
@@ -1119,7 +1113,7 @@ evoke any certain sensible data type.
 =item S
 
 Specifies a text input field (<INPUT TYPE=TEXT>).
-This use of the o conversion specifier is somewhat reasonable,
+This use of the S conversion specifier is somewhat reasonable,
 since text input fields contain values of undeterminable type,
 which can be treated as strings.