/XML-TreePP/t/09_http-lite.t

http://xml-treepp.googlecode.com/ · Raku · 43 lines · 37 code · 0 blank · 6 comment · 3 complexity · 8875fdc45c0e8cf6067fdd7a1a9e3156 MD5 · raw file

  1. # ----------------------------------------------------------------
  2. use strict;
  3. use Test::More;
  4. # ----------------------------------------------------------------
  5. SKIP: {
  6. local $@;
  7. eval { require HTTP::Lite; } unless defined $HTTP::Lite::VERSION;
  8. if ( ! defined $HTTP::Lite::VERSION ) {
  9. plan skip_all => 'HTTP::Lite is not loaded.';
  10. }
  11. if ( ! defined $ENV{MORE_TESTS} ) {
  12. plan skip_all => 'define $MORE_TESTS to test HTTP::Lite.';
  13. }
  14. plan tests => 5;
  15. use_ok('XML::TreePP');
  16. &parsehttp_get();
  17. &parsehttp_post();
  18. }
  19. # ----------------------------------------------------------------
  20. sub parsehttp_get {
  21. my $tpp = XML::TreePP->new();
  22. my $name = ( $0 =~ m#([^/:\\]+)$# )[0];
  23. $tpp->set( user_agent => "$name " );
  24. my $url = "http://use.perl.org/index.rss";
  25. my $tree = $tpp->parsehttp( GET => $url );
  26. ok( ref $tree, $url );
  27. like( $tree->{"rdf:RDF"}->{channel}->{link}, qr{^http://}, "$url link" );
  28. }
  29. # ----------------------------------------------------------------
  30. sub parsehttp_post {
  31. my $tpp = XML::TreePP->new( force_array => [qw( item )] );
  32. my $name = ( $0 =~ m#([^/:\\]+)$# )[0];
  33. $tpp->set( user_agent => "$name " );
  34. my $url = "http://search.hatena.ne.jp/keyword";
  35. my $query = "ajax";
  36. my $body = "mode=rss2&word=".$query;
  37. my $tree = $tpp->parsehttp( POST => $url, $body );
  38. ok( ref $tree, $url );
  39. like( $tree->{rss}->{channel}->{item}->[0]->{link}, qr{^http://}, "$url link" );
  40. }
  41. # ----------------------------------------------------------------
  42. ;1;
  43. # ----------------------------------------------------------------