xmltv/grab Get_nice.pm,1.27,1.28

Geoff <[email protected]>
Newsgroups gmane.comp.tv.xmltv.cvs
Message-ID <[email protected]>
Update of /cvsroot/xmltv/xmltv/grab
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16359

Modified Files:
	Get_nice.pm 
Log Message:
(minor) allow user-specified decode option (see v1.25)

Index: Get_nice.pm
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/Get_nice.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Get_nice.pm	21 Jan 2014 17:46:53 -0000	1.27
--- Get_nice.pm	23 Jan 2014 09:25:49 -0000	1.28
***************
*** 32,36 ****
  # use version number for feature detection:
  # 0.005065 : new methods get_nice_json(), get_nice_xml()
! # 0.005065 : add utf8 decode option to get_nice_tree()
  # 0.005065 : expose the LWP response object ($Response)
  our $VERSION = 0.005065;
--- 32,36 ----
  # use version number for feature detection:
  # 0.005065 : new methods get_nice_json(), get_nice_xml()
! # 0.005065 : add decode option to get_nice_tree()
  # 0.005065 : expose the LWP response object ($Response)
  our $VERSION = 0.005065;
***************
*** 68,82 ****
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming UTF-8 to UNICODE when set to 1
  #
  sub get_nice_tree( $;$$ ) {
!     my ($uri, $filter, $utf8) = @_;
      require HTML::TreeBuilder;
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     if ($utf8) {
        # (note: HTML::Parser->utf8_mode is only available Perl 5.8) 
        require Encode; import Encode;
!       $content = decode('UTF-8', $content);   # strict utf-8
      }
      my $t = HTML::TreeBuilder->new()->parse($content) or die "cannot parse content of $uri\n";
--- 68,82 ----
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming page to UNICODE using this codepage (use "UTF-8" for  strict utf-8)
  #
  sub get_nice_tree( $;$$ ) {
!     my ($uri, $filter, $codepage) = @_;
      require HTML::TreeBuilder;
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     if ($codepage) {
        # (note: HTML::Parser->utf8_mode is only available Perl 5.8) 
        require Encode; import Encode;
!       $content = decode($codepage, $content);
      }
      my $t = HTML::TreeBuilder->new()->parse($content) or die "cannot parse content of $uri\n";
***************
*** 89,102 ****
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming UTF-8 to UNICODE when set to 1
  #
  sub get_nice_xml( $;$$ ) {
!     my ($uri, $filter, $utf8) = @_;
      require XML::Parser;
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     if ($utf8) {
        require Encode; import Encode;
!       $content = decode('UTF-8', $content);   # strict utf-8
      }
      my $t = XML::Parser->new(Style => 'Tree')->parse($content) or die "cannot parse content of $uri\n";
--- 89,102 ----
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming page to UNICODE using this codepage (use "UTF-8" for  strict utf-8)
  #
  sub get_nice_xml( $;$$ ) {
!     my ($uri, $filter, $codepage) = @_;
      require XML::Parser;
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     if ($codepage) {
        require Encode; import Encode;
!       $content = decode($codepage, $content);
      }
      my $t = XML::Parser->new(Style => 'Tree')->parse($content) or die "cannot parse content of $uri\n";
***************
*** 108,112 ****
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming UTF-8 to UNICODE when set to 1
  #
  sub get_nice_json( $;$$ ) {
--- 108,112 ----
  # i) a function to put the page data through (eg, to clean up bad
  # characters) before parsing.
! # ii) convert incoming UTF-8 to UNICODE
  #
  sub get_nice_json( $;$$ ) {
***************
*** 115,119 ****
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     $utf8 = 0 if !defined $utf8; #(not necessary but safer)
      my $t = JSON::PP->new()->utf8($utf8)->decode($content) or die "cannot parse content of $uri\n";
      return $t;
--- 115,119 ----
      my $content = get_nice $uri;
      $content = $filter->($content) if $filter;
!     $utf8 = defined $utf8 ? 1 : 0;
      my $t = JSON::PP->new()->utf8($utf8)->decode($content) or die "cannot parse content of $uri\n";
      return $t;


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.