Moosify TWMC
[catagits/Test-WWW-Mechanize-Catalyst.git] / lib / Test / WWW / Mechanize / Catalyst.pm
index 72e4072..74e4758 100644 (file)
@@ -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<Test::WWW::Mechanize>, L<WWW::Mechanize>.
 
 =head1 AUTHOR
 
-Current Maintainer: Ash Berlin C<< <ash@cpan.org> >>
+Ash Berlin C<< <ash@cpan.org> >> (current maintiner)
 
-Leon Brocard, C<< <acme@astray.com> >>
+Original Author: Leon Brocard, C<< <acme@astray.com> >>
 
 =head1 COPYRIGHT