Changeset 1837

Show
Ignore:
Timestamp:
05/30/06 18:03:29
Author:
miyagawa
Message:

0.10: fixed globally_override

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • XML-Liberal/trunk/Changes

    r1836 r1837  
    11Revision history for Perl extension XML::Liberal 
     2 
     30.10  2006-05-30 18:02:51 JST 
     4        - Fixed globally_override to work with XML::RSS::LibXML and other tools that calls XML::LibXML::Parser methods. 
     5        - reorgainzed class strucure to make it simpler. 
    26 
    370.09  2006-05-26 17:05:00 JST 
  • XML-Liberal/trunk/MANIFEST

    r1834 r1837  
    11Changes 
    22lib/XML/Liberal.pm 
    3 lib/XML/Liberal/Driver.pm 
    43lib/XML/Liberal/LibXML.pm 
    54lib/XML/Liberal/Remedy.pm 
  • XML-Liberal/trunk/lib/XML/Liberal.pm

    r1836 r1837  
    22 
    33use strict; 
    4 our $VERSION = '0.09'; 
     4our $VERSION = '0.10'; 
    55 
    66use base qw( Class::Accessor ); 
     
    1313 
    1414__PACKAGE__->remedies(); # load remedies now 
    15 __PACKAGE__->mk_accessors(qw( max_fallback debug )); 
     15__PACKAGE__->mk_accessors(qw( max_fallback guess_encodings debug )); 
    1616 
    1717sub new { 
     
    2323 
    2424    my %param = @_; 
    25     my $max_fb = delete $param{max_fallback} || 15
     25    $param{max_fallback} = 15 unless defined $param{max_fallback}
    2626 
    27     bless { 
    28         driver => $subclass->new(%param), 
    29         max_fallback => $max_fb, 
    30     }, $class; 
     27    $subclass->new(%param); 
    3128} 
    3229 
     
    3835       $subclass->require or die $@; 
    3936 
    40     $subclass->do_globally_override; 
     37    $subclass->globally_override; 
    4138} 
    42  
    43 sub driver { $_[0]->{driver} } 
    4439 
    4540sub parse_string { 
     
    5247    TRY: { 
    5348        eval { 
    54             $doc = $self->driver->parse_string($xml); 
     49            $doc = $self->{parser}->parse_string($xml); 
    5550        }; 
    5651        last TRY if $doc || ($try++ > $self->max_fallback); 
    5752 
    5853        if ($@) { 
    59             my $remedy = $self->driver->handle_error($@); 
     54            my $remedy = $self->handle_error($@); 
    6055            if ($remedy) { 
    6156                warn "try fixing with ", ref($remedy) if $self->debug; 
     
    8277    my $xml = join '', <$fh>; 
    8378    $self->parse_string($xml); 
     79} 
     80 
     81our $AUTOLOAD; 
     82sub AUTOLOAD { 
     83    my($self, @args) = @_; 
     84    (my $meth = $AUTOLOAD) =~ s/.*:://; 
     85    $self->{parser}->$meth(@args); 
     86} 
     87 
     88sub DESTROY { 
     89    my $self = shift; 
     90    delete $self->{parser}; 
    8491} 
    8592 
  • XML-Liberal/trunk/lib/XML/Liberal/LibXML.pm

    r1834 r1837  
    55use XML::LibXML; 
    66 
    7 use base qw( XML::Liberal::Driver ); 
     7use base qw( XML::Liberal ); 
    88 
    99our $XML_LibXML_new; 
    1010 
    11 sub do_globally_override { 
     11sub globally_override { 
    1212    my $class = shift; 
    1313 
     
    2121} 
    2222 
    23 sub init { 
    24     my $self = shift; 
    25     $self->SUPER::init(); 
     23sub new { 
     24    my $class = shift; 
     25    my %param = @_; 
     26 
     27    my $self = bless { %param }, $class; 
    2628    $self->{parser} = $XML_LibXML_new 
    2729        ? $XML_LibXML_new->('XML::LibXML') : XML::LibXML->new; 
    28 } 
    2930 
    30 sub parse_string { 
    31     my $self = shift; 
    32     my($xml) = @_; 
    33     $self->{parser}->parse_string($xml); 
     31    $self; 
    3432} 
    3533 
     
    9896} 
    9997 
     98# recover() is not useful for Liberal parser ... IMHO 
     99sub recover { } 
     100 
    100101sub get_pos { 
    101102    my($self, $err) = @_; 
  • XML-Liberal/trunk/lib/XML/Liberal/Remedy/NotUTF8.pm

    r1797 r1837  
    1212    my($xml_ref) = @_; 
    1313 
    14     my @suspects = @{ $self->guess_encodings }; 
     14    my @suspects = @{ $self->guess_encodings || [ qw(euc-jp shift_jis utf-8) ] }; 
    1515    my $enc = guess_encoding($$xml_ref, @suspects); 
    1616    if (ref($enc)) { 
  • XML-Liberal/trunk/lib/XML/Liberal/Remedy/UndeclaredNS.pm

    r1835 r1837  
    2525    xhtml   => "http://www.w3.org/1999/xhtml", 
    2626    atom    => "http://www.w3.org/2005/Atom", 
     27    media   => "http://search.yahoo.com/mrss", 
     28    hatena  => "http://www.hatena.ne.jp/info/xmlns#", 
     29    'apple-wallpapers' => "http://www.apple.com/ilife/wallpapers", 
     30    itunes  => "http://www.itunes.com/dtds/podcast-1.0.dtd", 
    2731); 
    2832 
     
    4044    my $ns = $namespaces{$prefix} || 'http://example.org/unknown/$self->{prefix}#'; 
    4145 
    42     my $match = $$xml_ref =~ s!^(<\?xml .*?\?>\s+<.*?)>!$1 xmlns:$prefix="$ns">!s; 
     46    my $match = $$xml_ref =~ s!^(<\?xml .*?\?>\s*<.*?)>!$1 xmlns:$prefix="$ns">!s; 
    4347    return if $match; 
    4448