[Catalyst-commits] r6831 - in
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder: . lib lib/Test
lib/Test/WWW lib/Test/WWW/Mechanize
lib/Test/WWW/Mechanize/Catalyst t t/lib t/lib/TestApp
t/lib/TestApp/Controller
ash at dev.catalyst.perl.org
ash at dev.catalyst.perl.org
Mon Sep 3 20:40:24 GMT 2007
Author: ash
Date: 2007-09-03 20:40:24 +0100 (Mon, 03 Sep 2007)
New Revision: 6831
Added:
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/MANIFEST.SKIP
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/Makefile.PL
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/Catalyst/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/Catalyst/TreeBuilder.pm
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/01-basic.t
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp.pm
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/Controller/
trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/Controller/Root.pm
Log:
Initial revision
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/MANIFEST.SKIP
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/MANIFEST.SKIP (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/MANIFEST.SKIP 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,37 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\b\.#
+^\.DS_Store$
+\..*?\.swp$
+
+# Avoid Apache::Test files
+t/conf/apache_test_config.pm
+t/conf/extra.conf$
+t/conf/httpd.conf
+t/conf/mime.types
+t/htdocs
+t/logs
+t/var
+t/store
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/Makefile.PL
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/Makefile.PL (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/Makefile.PL 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,14 @@
+use inc::Module::Install;
+
+name 'Test-WWW-Mechanize-Catalyst-TreeBuilder';
+all_from 'lib/Test/WWW/Mechanize/Catalyst/TreeBuilder.pm';
+
+requires 'perl' => '5.8.1';
+requires 'Test::WWW::Mechanize::Catalyst' => '5.7';
+requires 'Moose' => 0;
+
+build_requires 'Test::More';
+
+no_index directory => 't/lib';
+
+WriteAll;
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/Catalyst/TreeBuilder.pm
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/Catalyst/TreeBuilder.pm (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/lib/Test/WWW/Mechanize/Catalyst/TreeBuilder.pm 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,40 @@
+package Test::WWW::Mechanize::Catalyst::TreeBuilder;
+
+use Moose;
+use HTML::TreeBuilder;
+
+our $VERSION = 1.00000;
+
+extends 'Test::WWW::Mechanize::Catalyst';
+
+has 'tree' => (
+ is => 'ro',
+ isa => 'HTML::Element',
+ writer => '_set_tree',
+ lazy => 1,
+ default => sub { new HTML::TreeBuilder },
+ handles => [ qw/look_down find/ ],
+);
+
+around '_make_request' => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $ret = $self->$orig(@_);
+
+ # Someone needs to learn about weak refs
+ $self->tree->delete if $self->tree;
+
+ if ($ret->header('content-type') =~ m[^(text/html|application/(?:.*?\+)xml)]) {
+ $self->_set_tree( HTML::TreeBuilder->new_from_content($ret->decoded_content)->elementify );
+ }
+
+ return $ret;
+};
+
+sub DEMOLISH {
+ my $self = shift;
+ warn "DEMOLISH\n";
+ $self->tree->delete if $self->tree;
+}
+
+1;
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/01-basic.t
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/01-basic.t (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/01-basic.t 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../t/lib";
+use Test::More tests => 4;
+
+BEGIN { use_ok 'Test::WWW::Mechanize::Catalyst::TreeBuilder', 'TestApp'; }
+
+my $mech = Test::WWW::Mechanize::Catalyst::TreeBuilder->new;
+
+$mech->get_ok('/');
+
+isa_ok($mech->tree, 'HTML::Element');
+
+is($mech->look_down(_tag => 'p')->as_trimmed_text, 'A para');
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/Controller/Root.pm (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp/Controller/Root.pm 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,27 @@
+package TestApp::Controller::Root;
+use strict;
+use warnings;
+
+__PACKAGE__->config(namespace => '');
+
+use base 'Catalyst::Controller';
+
+# your actions replace this one
+sub main :Path {
+ $_[1]->res->content_type('text/html; charset=utf-8');
+ $_[1]->res->body(<<'EOF');
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+ <title>Hurrah!</title>
+</head>
+<body>
+ <h1>It works</h1>
+ <p>A para</p>
+</body>
+</html>
+EOF
+}
+
+1;
Added: trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp.pm
===================================================================
--- trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp.pm (rev 0)
+++ trunk/Test-WWW-Mechanize-Catalyst-TreeBuilder/t/lib/TestApp.pm 2007-09-03 19:40:24 UTC (rev 6831)
@@ -0,0 +1,9 @@
+package TestApp;
+use strict;
+use warnings;
+
+use Catalyst;
+
+__PACKAGE__->setup;
+
+1;
More information about the Catalyst-commits
mailing list