Imported Upstream version 3.42 upstream/3.42
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 25 Jul 2022 02:23:11 +0000 (11:23 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 25 Jul 2022 02:23:11 +0000 (11:23 +0900)
Changes
META.json
META.yml
Makefile.PL
Twig.pm
Twig_pm.slow
speedup

diff --git a/Changes b/Changes
index 034db9f..69abe38 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,18 @@
-$Id: /xmltwig/trunk/Changes 33 2008-04-30T08:03:41.004487Z mrodrigu  $
-
 CHANGES
+
+version 3.42
+date: 2012-11-06
+# minor maintenance release
+fixed: bug, elements created with XML::Twig::Elt->parse were 
+       garbage collected too early, 
+       see http://stackoverflow.com/questions/13263193/xmltwig-changes-erased
+added: some tests
+
+version 3.41
+date 2012-08-08
+# minor maintenance release
+fixed: META.json generation
+
 version 3.40
 date: 2012-05-10
 # minor maintenance release
index 9fe927c..a08496b 100644 (file)
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Michel Rodriguez <mirod@cpan.org>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921",
+   "generated_by" : "ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921",
    "license" : [
       "perl_5"
    ],
@@ -42,5 +42,5 @@
          "url" : "http://github.com/mirod/xmltwig"
       }
    },
-   "version" : "3.41"
+   "version" : "3.42"
 }
index 3c19e06..8375697 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -7,7 +7,7 @@ build_requires:
 configure_requires:
   ExtUtils::MakeMaker: 0
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921'
+generated_by: 'ExtUtils::MakeMaker version 6.6302, CPAN::Meta::Converter version 2.120921'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -21,4 +21,4 @@ requires:
   XML::Parser: 2.23
 resources:
   repository: http://github.com/mirod/xmltwig
-version: 3.41
+version: 3.42
index e8848ad..36c475c 100644 (file)
@@ -144,10 +144,11 @@ sub add_prereqs_to_mymeta
     rename $MYYAML, $YAML;
     if( eval { require JSON; })
       { my $json= JSON->new()->pretty->canonical;
-        my $meta= $json->decode( slurp( $MYJSON));
-        $meta->{prereqs}= $prereqs;
-        spit( $JSON, $json->encode( $meta));
-        warn "updated prereqs in $JSON\n";
+        if( my $meta= eval { $json->decode( slurp( -s $MYJSON ?  $MYJSON : $JSON )); })
+          { $meta->{prereqs}= $prereqs;
+            spit( $JSON, $json->encode( $meta));
+            warn "updated prereqs in $JSON\n";
+          }
       }
 
   }
diff --git a/Twig.pm b/Twig.pm
index 885714b..2e7f1c5 100644 (file)
--- a/Twig.pm
+++ b/Twig.pm
@@ -124,7 +124,7 @@ my $SEP= qr/\s*(?:$|\|)/;
 
 BEGIN
 { 
-$VERSION = '3.41';
+$VERSION = '3.42';
 
 use XML::Parser;
 my $needVersion = '2.23';
@@ -681,7 +681,7 @@ sub new
 
     if( my $acc_a= $args{AttAccessors})   { $self->att_accessors( @$acc_a);  }
     if( my $acc_e= $args{EltAccessors})   { $self->elt_accessors( isa( $acc_e, 'ARRAY') ? @$acc_e : $acc_e);   }
-    if( my $acc_f= $args{FieldAccessors}) { $self->field_accessors( @$acc_f); }
+    if( my $acc_f= $args{FieldAccessors}) { $self->field_accessors( isa( $acc_f, 'ARRAY') ? @$acc_f : $acc_f); }
 
     if( $args{UseTidy}) { $self->{use_tidy}= 1; }
     $self->{tidy_options}= $args{TidyOptions} || {};
@@ -3518,27 +3518,27 @@ sub field_accessors
     my $elt_class= ref $twig_or_class ? $twig_or_class->{twig_elt_class}
                                       : 'XML::Twig::Elt'
                                       ;
+    my %exp_to_alias= ref( $_[0]) && isa( $_[0], 'HASH') ? %{$_[0]}
+                                                         : map { $_ => $_ } @_;
+
     ## no critic (TestingAndDebugging::ProhibitNoStrict);
     no strict 'refs';
-    foreach my $exp (@_)
-      { _croak( "attempt to redefine existing method $exp using field_accessors")
-          if( $elt_class->can( $exp) && !$accessor{$exp});
-
-        if( !$accessor{$exp})                                
-          { *{"$elt_class\::$exp"}=                          
+    while( my( $alias, $exp)= each %exp_to_alias )
+      { if( $elt_class->can( $alias) && !$accessor{$alias})
+          { _croak( "attempt to redefine existing method $exp using field_accessors"); }
+        if( !$accessor{$alias})                                
+          { *{"$elt_class\::$alias"}=                          
                 sub                                          
                   { my $elt= shift;                          
                     $elt->field( $exp)                       
                   };                                         
-            $accessor{$exp}=1;                               
+            $accessor{$alias}=1;                               
           }                                                  
       }
     return $twig_or_class;
   }
 }
 
-
-
 sub first_elt
   { my( $t, $cond)= @_;
     my $root= $t->root || return undef;
@@ -4962,6 +4962,8 @@ sub parse
     delete $elt->{twig};         # get rid of the twig data
     delete $elt->{twig_current}; # better get rid of this too
     if( $t->{twig_id_list}) { $elt->{twig_id_list}= $t->{twig_id_list}; }
+    $elt->cut; 
+    undef $t->{twig_root};
     return $elt;
   }
    
@@ -9506,12 +9508,14 @@ Huge documents (processed in combined stream/tree mode):
     pretty_print => 'indented',                # output will be nicely formatted
     empty_tags   => 'html',                    # outputs <empty_tag />
                          );
-    $twig->flush;                              # flush the end of the document
+  $twig->parsefile( 'my_big.xml');
 
 See L<XML::Twig 101|/XML::Twig 101> for other ways to use the module, as a 
 filter for example.
 
 
+=encoding utf8
+
 =head1 DESCRIPTION
 
 This module provides a way to process XML documents. It is build on top
@@ -9592,8 +9596,6 @@ relevant element has been parsed.
                           },
                        );
   $t->parsefile( 'doc.xml');
-  $t->flush; # don't forget to flush one last time in the end or anything
-             # after the last </section> tag will not be output 
 
   # the handler is called once a section is completely parsed, ie when 
   # the end tag for section is found, it receives the twig itself and
@@ -11058,6 +11060,9 @@ The doctype and entity declarations are also printed.
 
 flush take an optional filehandle as an argument.
 
+If you use C<flush> at any point during parsing, the document will be flushed
+one last time at the end of the parsing, to the proper filehandle.
+
 options: use the C<update_DTD> option if you have updated the (internal) DTD 
 and/or the entity list and you want the updated DTD to be output 
 
@@ -13540,14 +13545,11 @@ If you need to modify the entity list this is probably the easiest way to do it.
 
 =head2 Flush
 
-If you set handlers and use C<flush>, do not forget to flush the twig one
-last time AFTER the parsing, or you might be missing the end of the document.
-
 Remember that element handlers are called when the element is CLOSED, so
 if you have handlers for nested elements the inner handlers will be called
 first. It makes it for example trickier than it would seem to number nested
-clauses.
-
+sections (or clauses, or divs), as the titles in the inner sections are handled
+before the outer sections.
 
 
 =head1 BUGS
index d90b16d..4e41fc8 100755 (executable)
@@ -124,7 +124,7 @@ my $SEP= qr/\s*(?:$|\|)/;
 
 BEGIN
 { 
-$VERSION = '3.41';
+$VERSION = '3.42';
 
 use XML::Parser;
 my $needVersion = '2.23';
@@ -681,7 +681,7 @@ sub new
 
     if( my $acc_a= $args{AttAccessors})   { $self->att_accessors( @$acc_a);  }
     if( my $acc_e= $args{EltAccessors})   { $self->elt_accessors( isa( $acc_e, 'ARRAY') ? @$acc_e : $acc_e);   }
-    if( my $acc_f= $args{FieldAccessors}) { $self->field_accessors( @$acc_f); }
+    if( my $acc_f= $args{FieldAccessors}) { $self->field_accessors( isa( $acc_f, 'ARRAY') ? @$acc_f : $acc_f); }
 
     if( $args{UseTidy}) { $self->{use_tidy}= 1; }
     $self->{tidy_options}= $args{TidyOptions} || {};
@@ -3519,27 +3519,27 @@ sub field_accessors
     my $elt_class= ref $twig_or_class ? $twig_or_class->{twig_elt_class}
                                       : 'XML::Twig::Elt'
                                       ;
+    my %exp_to_alias= ref( $_[0]) && isa( $_[0], 'HASH') ? %{$_[0]}
+                                                         : map { $_ => $_ } @_;
+
     ## no critic (TestingAndDebugging::ProhibitNoStrict);
     no strict 'refs';
-    foreach my $exp (@_)
-      { _croak( "attempt to redefine existing method $exp using field_accessors")
-          if( $elt_class->can( $exp) && !$accessor{$exp});
-
-        if( !$accessor{$exp})                                
-          { *{"$elt_class\::$exp"}=                          
+    while( my( $alias, $exp)= each %exp_to_alias )
+      { if( $elt_class->can( $alias) && !$accessor{$alias})
+          { _croak( "attempt to redefine existing method $exp using field_accessors"); }
+        if( !$accessor{$alias})                                
+          { *{"$elt_class\::$alias"}=                          
                 sub                                          
                   { my $elt= shift;                          
                     $elt->field( $exp)                       
                   };                                         
-            $accessor{$exp}=1;                               
+            $accessor{$alias}=1;                               
           }                                                  
       }
     return $twig_or_class;
   }
 }
 
-
-
 sub first_elt
   { my( $t, $cond)= @_;
     my $root= $t->root || return undef;
@@ -4963,6 +4963,8 @@ sub parse
     delete $elt->{twig};         # get rid of the twig data
     delete $elt->{twig_current}; # better get rid of this too
     if( $t->{twig_id_list}) { $elt->{twig_id_list}= $t->{twig_id_list}; }
+    $elt->cut; 
+    undef $t->{twig_root};
     return $elt;
   }
    
@@ -9508,12 +9510,14 @@ Huge documents (processed in combined stream/tree mode):
     pretty_print => 'indented',                # output will be nicely formatted
     empty_tags   => 'html',                    # outputs <empty_tag />
                          );
-    $twig->flush;                              # flush the end of the document
+  $twig->parsefile( 'my_big.xml');
 
 See L<XML::Twig 101|/XML::Twig 101> for other ways to use the module, as a 
 filter for example.
 
 
+=encoding utf8
+
 =head1 DESCRIPTION
 
 This module provides a way to process XML documents. It is build on top
@@ -9594,8 +9598,6 @@ relevant element has been parsed.
                           },
                        );
   $t->parsefile( 'doc.xml');
-  $t->flush; # don't forget to flush one last time in the end or anything
-             # after the last </section> tag will not be output 
 
   # the handler is called once a section is completely parsed, ie when 
   # the end tag for section is found, it receives the twig itself and
@@ -11060,6 +11062,9 @@ The doctype and entity declarations are also printed.
 
 flush take an optional filehandle as an argument.
 
+If you use C<flush> at any point during parsing, the document will be flushed
+one last time at the end of the parsing, to the proper filehandle.
+
 options: use the C<update_DTD> option if you have updated the (internal) DTD 
 and/or the entity list and you want the updated DTD to be output 
 
@@ -13542,14 +13547,11 @@ If you need to modify the entity list this is probably the easiest way to do it.
 
 =head2 Flush
 
-If you set handlers and use C<flush>, do not forget to flush the twig one
-last time AFTER the parsing, or you might be missing the end of the document.
-
 Remember that element handlers are called when the element is CLOSED, so
 if you have handlers for nested elements the inner handlers will be called
 first. It makes it for example trickier than it would seem to number nested
-clauses.
-
+sections (or clauses, or divs), as the titles in the inner sections are handled
+before the outer sections.
 
 
 =head1 BUGS
diff --git a/speedup b/speedup
index 5a47e5d..863fe46 100644 (file)
--- a/speedup
+++ b/speedup
@@ -14,7 +14,7 @@ print STDERR "perl version is $]\n";
 
 my $var= '(\$[a-z_]+(?:\[\d\])?)';
 
-my $set_to = '(?:undef|\$\w+|\$\w+->{\w+}|\$\w+->\w+|\$\w+->\w+\([^)]+\))';
+my $set_to = '(?:undef|\$\w+|\$\w+->\{\w+\}|\$\w+->\w+|\$\w+->\w+\([^)]+\))';
 my $elt    = '\$(?:elt|new_elt|child|cdata|ent|_?parent|twig_current|next_sibling|first_child|prev_sibling|last_child|ref|elt->_parent)';
 
 
@@ -49,10 +49,10 @@ while( <>)
 
     s{($elt)->former_($FORMER)}{($1\->{former} && $1\->{former}\->{$2})}g;
 
-    s{($elt)->set_(parent|prev_sibling)\(\s*($set_to)\s*\)}{$1\->{$2}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->{$2});} }g;
-    s{($elt)->set_(first_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->{$2}=$3; }g;
-    s{($elt)->set_(next_sibling)\(\s*($set_to)\s*\)}{ $1\->{$2}=$3; }g;
-    s{($elt)->set_(last_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->{$2}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->{$2});} }g;
+    s{($elt)->set_(parent|prev_sibling)\(\s*($set_to)\s*\)}{$1\->\{$2\}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->\{$2\});} }g;
+    s{($elt)->set_(first_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->\{$2\}=$3; }g;
+    s{($elt)->set_(next_sibling)\(\s*($set_to)\s*\)}{ $1\->\{$2\}=$3; }g;
+    s{($elt)->set_(last_child)\(\s*($set_to)\s*\)}{ $1\->set_not_empty; $1\->\{$2\}=$3; if( \$XML::Twig::weakrefs) { weaken( $1\->\{$2\});} }g;
 
     s/$var->atts/$1\->{att}/g;