-$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
"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"
],
"url" : "http://github.com/mirod/xmltwig"
}
},
- "version" : "3.41"
+ "version" : "3.42"
}
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
XML::Parser: 2.23
resources:
repository: http://github.com/mirod/xmltwig
-version: 3.41
+version: 3.42
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";
+ }
}
}
BEGIN
{
-$VERSION = '3.41';
+$VERSION = '3.42';
use XML::Parser;
my $needVersion = '2.23';
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} || {};
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;
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;
}
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
},
);
$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
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
=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
BEGIN
{
-$VERSION = '3.41';
+$VERSION = '3.42';
use XML::Parser;
my $needVersion = '2.23';
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} || {};
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;
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;
}
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
},
);
$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
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
=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
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)';
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;