X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FTest-WWW-Mechanize-Catalyst.git;a=blobdiff_plain;f=lib%2FTest%2FWWW%2FMechanize%2FCatalyst.pm;h=74e4758b950f250d3eb6c5920b9b4bd80e49f5f4;hp=72e4072c358911e2be0da9ae7111b4843bc30fdd;hb=f21ad4062cdd3485f59635926fa031feef7eff8e;hpb=254eca4135088b598bc59093b98475992b4bf6f5 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