From: Ash Berlin Date: Wed, 4 Feb 2009 20:10:18 +0000 (+0000) Subject: Moosify TWMC X-Git-Tag: 0.51~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FTest-WWW-Mechanize-Catalyst.git;a=commitdiff_plain;h=f21ad4062cdd3485f59635926fa031feef7eff8e Moosify TWMC --- diff --git a/Makefile.PL b/Makefile.PL index 61aa05e..9399a41 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,23 +1,22 @@ #!perl +use inc::Module::Install 0.77; + use strict; use warnings; -use ExtUtils::MakeMaker; -WriteMakefile( - 'NAME' => 'Test::WWW::Mechanize::Catalyst', - 'VERSION_FROM' => 'lib/Test/WWW/Mechanize/Catalyst.pm', - 'AUTHOR' => 'Leon Brocard ', - 'ABSTRACT' => 'Test::WWW::Mechanize for Catalyst', - 'LICENSE' => 'perl', - 'PREREQ_PM' => { - 'Catalyst' => '5.00', - 'Catalyst::Plugin::Session::State::Cookie' => '0', - 'Catalyst::Plugin::Session::Store::Dummy' => '0', - 'LWP' => '5.816', - 'Test::Exception' => '0', - 'Test::More' => '0', - 'Test::WWW::Mechanize' => '1.14', - 'WWW::Mechanize' => '1.50', - }, -); +name 'Test-WWW-Mechanize-Catalyst'; +all_from 'lib/Test/WWW/Mechanize/Catalyst.pm'; + +requires 'Catalyst' => '5.00'; +requires 'LWP' => '5.816'; +requires 'Test::WWW::Mechanize' => '1.14'; +requires 'WWW::Mechanize' => '1.50'; +requires 'Moose' => '0.67'; +requires 'namespace::clean' => '0.09'; + +test_requires 'Catalyst::Plugin::Session::State::Cookie' => '0'; +test_requires 'Catalyst::Plugin::Session::Store::Dummy' => '0'; +test_requires 'Test::Exception' => '0'; +test_requires 'Test::More' => '0'; +WriteAll; diff --git a/lib/Test/WWW/Mechanize/Catalyst.pm b/lib/Test/WWW/Mechanize/Catalyst.pm index 72e4072..74e4758 100644 --- a/lib/Test/WWW/Mechanize/Catalyst.pm +++ b/lib/Test/WWW/Mechanize/Catalyst.pm @@ -1,7 +1,6 @@ package Test::WWW::Mechanize::Catalyst; -use strict; -use warnings; +use Moose; use Carp qw/croak/; require Catalyst::Test; # Do not call import @@ -9,39 +8,39 @@ use Encode qw(); use HTML::Entities; use Test::WWW::Mechanize; -use base qw(Test::WWW::Mechanize); +extends 'Test::WWW::Mechanize', 'Moose::Object'; + +use namespace::clean -execept => 'meta'; our $VERSION = '0.45'; +our $APP_CLASS; my $Test = Test::Builder->new(); -# the reason for the auxiliary package is that both WWW::Mechanize and -# Catalyst::Test have a subroutine named 'request' +has catalyst_app => ( + is => 'ro', + required => 1, + default => sub { $APP_CLASS }, +); + +has allow_external => ( + is => 'rw', + isa => 'Bool', + default => 0 +); -our $APP_CLASS; sub new { - my ($class, %args) = @_; - - my $app; - if (exists $args{catalyst_app}) { - $app = $args{catalyst_app}; - - require Class::Inspector->filename( $app ) - unless Class::Inspector->loaded( $app ); - } elsif (!defined $APP_CLASS) { - croak 'Please provide a catalyst_app option or import Test::WWW::Mechanize::Catalyst with a class name'; - } else { - $app = $APP_CLASS; - } + my $class = shift; - my $self = $class->SUPER::new(%args); - $self->{catalyst_app} = $app; - return $self; -} + my $obj = $class->SUPER::new(@_); + my $self = $class->meta->new_object( + __INSTANCE__ => $obj, + @_ + ); + + Class::MOP::load_class($self->catalyst_app) + unless (Class::MOP::is_class_loaded($self->catalyst_app)); -sub allow_external { - my ( $self, $value ) = @_; - return $self->{allow_external} unless defined $value; - $self->{allow_external} = $value; + return $self; } sub _make_request { @@ -120,11 +119,13 @@ sub _make_request { sub import { my ($class, $app) = @_; + if (defined $app) { - require Class::Inspector->filename( $app ) - unless Class::Inspector->loaded( $app ); + Class::MOP::load_class($app) + unless (Class::MOP::is_class_loaded($app)); $APP_CLASS = $app; } + } @@ -378,9 +379,9 @@ L, L. =head1 AUTHOR -Current Maintainer: Ash Berlin C<< >> +Ash Berlin C<< >> (current maintiner) -Leon Brocard, C<< >> +Original Author: Leon Brocard, C<< >> =head1 COPYRIGHT