Subject: | Doc fixes |
Here are some techinical fixes for your documentation where code
snippets - including examples - had syntax errors:
--- a/XML/Twig.pm 2013-02-11 15:13:43.231156933 +0100
+++ b/XML/Twig.pm 2013-02-11 15:34:48.111256684 +0100
@@ -9948,7 +9948,7 @@ confuse XML::Twig ;--(
Note: you can set handlers (twig_handlers) using twig_roots
Example: my $t= XML::Twig->new( twig_roots =>
- { title => sub { $_{1]->print;},
+ { title => sub { $_[1]->print;},
subtitle => \&process_subtitle
}
);
@@ -9968,7 +9968,7 @@ value this will print the document outsi
sub number_title
{ my( $twig, $title);
$nb++;
- $title->prefix( "$nb "; }
+ $title->prefix( "$nb ");
$title->print;
}
}
@@ -9991,7 +9991,7 @@ C<twig_roots> elements will be output to
sub number_title
{ my( $twig, $title);
$nb++;
- $title->prefix( "$nb "; }
+ $title->prefix( "$nb ");
$title->print( $out); # you have to print to \*OUT
here
}
}
@@ -10610,14 +10610,14 @@ example:
# using an array ref
my $t= XML::Twig->new( index => [ 'div', 'table' ])
- ->parsefile( "foo.xml');
+ ->parsefile( "foo.xml");
my $divs= $t->index( 'div');
my $first_div= $divs->[0];
my $last_table= $t->index( table => -1);
# using a hashref to name the indexes
- my $t= XML::Twig->new( index => { email => 'a[@href=~/^\s*mailto:/]')
- ->parsefile( "foo.xml');
+ my $t= XML::Twig->new( index => { email => 'a[@href=~/^
\s*mailto:/]'})
+ ->parsefile( "foo.xml");
my $last_emails= $t->index( email => -1);
Note that the index is not maintained after the parsing. If elements
are
@@ -10630,7 +10630,7 @@ creates methods that give direct access
my $t= XML::Twig->new( att_accessors => [ 'href', 'src'])
->parsefile( $file);
- my $first href= $t->first_elt( 'img')->src; # same as ->att( 'src')
+ my $first_href= $t->first_elt( 'img')->src; # same as ->att( 'src')
$t->first_elt( 'img')->src( 'new_logo.png') # changes the attribute
value
=item elt_accessors
@@ -10645,7 +10645,7 @@ or in a hash alias => expression
my $title_text= $t->root->head->field( 'title');
# same as $title_text= $t->root->first_child( 'head')->field
( 'title');
- my $t= XML::Twig->new( elt_accessors => { warnings => 'p
[@class="warning"]', d2 => 'div[2]', )
+ my $t= XML::Twig->new( elt_accessors => { warnings => 'p
[@class="warning"]', d2 => 'div[2]', })
->parsefile( $file);
my $body= $t->first_elt( 'body');
my @warnings= $body->warnings; # same as $body->children( 'p
[@class="warning"]');
@@ -11747,7 +11747,7 @@ The C<$optional_elt> is the root of a su
subtree then the method returns undef. You can then walk a sub-tree
with:
my $elt= $subtree_root;
- while( $elt= $elt->next_elt( $subtree_root)
+ while( $elt= $elt->next_elt( $subtree_root))
{ # insert processing code here
}
@@ -12321,8 +12321,8 @@ of the element.
B<Bug>: in the C<$regexp>, you can only use C<\1>, C<\2>... if the
replacement
expression does not include elements or attributes. eg
- t->subs_text( qr/((t[aiou])\2)/, '$2'); # ok, replaces
toto, tata, titi, tutu by to, ta, ti, tu
- t->subs_text( qr/((t[aiou])\2)/, '&elt(p => $1)' ); # NOK, does not
find toto...
+ $t->subs_text( qr/((t[aiou])\2)/, '$2'); # ok, replaces
toto, tata, titi, tutu by to, ta, ti, tu
+ $t->subs_text( qr/((t[aiou])\2)/, '&elt(p => $1)' ); # NOK, does not
find toto...
=item add_id ($optional_coderef)
@@ -12564,7 +12564,7 @@ table for example.
Optionally each tag can be followed by a hashref of attributes, that
will be
set on the wrapping element:
- $elt->wrap_in( p => { class => "advisory" }, div => { class =>
"intro", id => "div_intro });
+ $elt->wrap_in( p => { class => "advisory" }, div => { class =>
"intro", id => "div_intro" });
=item insert_new_elt ($opt_position, $tag, $opt_atts_hashref,
@opt_content)
-->8---