XML-Atom-Syndication

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Added inner_atom method to the feed, entry and source classes + tests
    - A few more documentation fixes

0.93 Jul 21 2006
    - Documentation fixes. (Thanks to John Gruber and gdsotirov)
    - Fixed bug were I misread section 3.1.1.3 and was wrapping XHTML 
      content in divs. Also updated related tests.
    - Fixed bug in XML::Atom::Syndication::Text were Encode was not loaded 
      before being used. Because of Encode's extensive use this problem is 
      only apparent under certain conditions.
    - Added no_cdata method to XML::Atom::Syndication::Writer. 

0.92 Jun 17 2006
    - Found a bug in XML::Writer::characters. Now handling encoding of character 
      data ourselves. Subsequentally was performing inline_markup_2 test 
      incorrectly. Fixed those also.
    
0.91 Jun 17 2006
    - Added conditional use of Encode to XML::Atom::Syndication::Content so 
      module won't fail when used with versions prior to Perl 5.8

lib/XML/Atom/Syndication/Text.pm  view on Meta::CPAN

                  @{$elem->contents};
                if (@children) {
                    my ($local) =
                      $children[0]->name =~ /{.*}(.+)/;    # process name
                    @children = @{$children[0]->contents}
                      if (@children == 1 && $local eq 'div');

                    # $text->{__body} = '<div>';
                    my $w = XML::Atom::Syndication::Writer->new;
                    $w->set_prefix('', 'http://www.w3.org/1999/xhtml');
                    $w->no_cdata(1);  # works nicer with fringe case. see tests.
                    map { $text->{__body} .= $w->as_xml($_) } @children;

                    # $text->{__body} .= '</div>';
                } else {
                    $text->{__body} = $elem->text_content;
                }
                if ($] >= 5.008) {
                    require Encode;
                    Encode::_utf8_on($text->{__body});
                    $text->{__body} =~ s/&#x(\w{4});/chr(hex($1))/eg;

lib/XML/Atom/Syndication/Writer.pm  view on Meta::CPAN

}

sub set_prefix {
    $_[0]->{__NS}->{$_[2]}     = $_[1];
    $_[0]->{__PREFIX}->{$_[1]} = $_[2];
}

sub get_prefix    { $_[0]->{__NS}->{$_[1]} }
sub get_namespace { $_[0]->{__PREFIX}->{$_[1]} }

sub no_cdata {
    if (defined $_[1]) {
        $_[0]->{__NO_CDATA} = $_[1] ? 1 : 0;
    }
    $_[0]->{__NO_CDATA};
}

sub as_xml {
    my ($self, $node, $is_full) = @_;
    my $xml = '';
    my $w;

lib/XML/Atom/Syndication/Writer.pm  view on Meta::CPAN

           '&'  => '&amp;',
           '"'  => '&quot;',
           '<'  => '&lt;',
           '>'  => '&gt;',
           '\'' => '&apos;'
);
my $RE = join '|', keys %Map;

sub encode_xml
{    # XML::Writer::character encoding is wrong so we handle this ourselves.
    my ($w, $str, $nocdata) = @_;
    return '' unless defined $str;
    if (
        !$nocdata
        && $str =~ m/
        <[^>]+>  ## HTML markup
        |        ## or
        &(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?);
                 ## something that looks like an HTML entity.
    /x
      ) {
        ## If ]]> exists in the string, encode the > to &gt;.
        $str =~ s/]]>/]]&gt;/g;
        $str = '<![CDATA[' . $str . ']]>';
      } else {
        $str =~ s!($RE)!$Map{$1}!g;
    }
    $w->raw($str);    # forces UNSAFE mode at all times.
}

1;

__END__

# utility for intelligent use of cdata.
sub encode_xml {
    my ($w, $data, $nocdata) = @_;
    return unless defined($data);
    if (
        !$nocdata
        && $data =~ m/
        <[^>]+>  ## HTML markup
        |        ## or
        &(?:(?!(\#([0-9]+)|\#x([0-9a-fA-F]+))).*?);
                 ## something that looks like an HTML entity.
    /x
      ) {

# $w->cdata($data); # this was inserting a extra character into returned strings.
        my $str = $w->characters($data);
        $str =~ s/]]>/]]&gt;/g;
        '<![CDATA[' . $str . ']]>';
      } else {
        $w->characters($data);
    }
}

=head1 NAME

lib/XML/Atom/Syndication/Writer.pm  view on Meta::CPAN

=item $writer->as_xml($node,$is_full)

Returns an XML representation of the given node and all its
descendants. By default the method returns an XML fragment
unless C<$is_full> is a true value. If C<$is_full> is true
an XML declaration is prepended to the output. 

All output will be in UTF-8 regardless of the original
encoding before parsing.

=item $writer->no_cdata([$boolean])

Defines the use of the CDATA construct for encoding 
embedded markup. By default this flag is set to false in 
which case CDATA will be used to  escape what looks like 
markup instead of using entity encoding. The purpose is that 
CDATA is more concise, readable and requires less processing.
This is not always desirable this can be turned off by passing 
in a true value. If nothing is passed the current state of 
CDATA use is returned.



( run in 0.238 second using v1.01-cache-2.11-cpan-454fe037f31 )