Permalink
Browse files

New release

  • Loading branch information...
1 parent 722a3e1 commit 9cb6fa17213b255052971b6672c8c6d78861b4d3 @exodist committed Jan 31, 2013
Showing with 39 additions and 25 deletions.
  1. +15 −15 lib/Mock/Quick.pm
  2. +9 −2 lib/Mock/Quick/Method.pm
  3. +4 −5 t/Method.t
  4. +11 −3 t/Object-Quick.t
View
@@ -8,43 +8,43 @@ use Mock::Quick::Object::Control;
use Mock::Quick::Method;
use Mock::Quick::Util;
-our $VERSION = '1.104';
+our $VERSION = '1.105';
-default_export qclass => sub { Mock::Quick::Class->new( @_ ) };
-default_export qtakeover => sub { Mock::Quick::Class->takeover( @_ ) };
-default_export qimplement => sub { Mock::Quick::Class->implement( @_ ) };
-default_export qcontrol => sub { Mock::Quick::Object::Control->new( @_ ) };
+default_export qclass => sub { Mock::Quick::Class->new(@_) };
+default_export qtakeover => sub { Mock::Quick::Class->takeover(@_) };
+default_export qimplement => sub { Mock::Quick::Class->implement(@_) };
+default_export qcontrol => sub { Mock::Quick::Object::Control->new(@_) };
default_export qobj => sub {
- my $obj = Mock::Quick::Object->new( @_ );
- my $control = Mock::Quick::Object::Control->new( $obj );
+ my $obj = Mock::Quick::Object->new(@_);
+ my $control = Mock::Quick::Object::Control->new($obj);
$control->strict(0);
return $obj;
};
default_export qobjc => sub {
- my $obj = Mock::Quick::Object->new( @_ );
- my $control = Mock::Quick::Object::Control->new( $obj );
+ my $obj = Mock::Quick::Object->new(@_);
+ my $control = Mock::Quick::Object::Control->new($obj);
$control->strict(0);
return ( $obj, $control );
};
default_export qstrict => sub {
- my $obj = Mock::Quick::Object->new( @_ );
- my $control = Mock::Quick::Object::Control->new( $obj );
+ my $obj = Mock::Quick::Object->new(@_);
+ my $control = Mock::Quick::Object::Control->new($obj);
$control->strict(1);
return $obj;
};
default_export qstrictc => sub {
- my $obj = Mock::Quick::Object->new( @_ );
- my $control = Mock::Quick::Object::Control->new( $obj );
+ my $obj = Mock::Quick::Object->new(@_);
+ my $control = Mock::Quick::Object::Control->new($obj);
$control->strict(1);
return ( $obj, $control );
};
-default_export qclear => sub { \$Mock::Quick::Util::CLEAR };
-default_export qmeth => sub(&){ Mock::Quick::Method->new( @_ )};
+default_export qclear => sub { \$Mock::Quick::Util::CLEAR };
+default_export qmeth => sub(&) { Mock::Quick::Method->new(@_) };
purge_util();
View
@@ -2,12 +2,19 @@ package Mock::Quick::Method;
use strict;
use warnings;
-use Carp ();
+use Carp ();
+use Scalar::Util ();
sub new {
my $class = shift;
my ($sub) = @_;
- return $sub if eval {$sub->isa($class)};
+
+ # Fixes #11
+ return $sub
+ if $sub
+ && Scalar::Util::blessed($sub)
+ && $sub->isa($class);
+
Carp::croak "Constructor to $class takes a single codeblock"
unless ref $sub eq 'CODE';
return bless $sub, $class;
View
@@ -10,19 +10,18 @@ our $CLASS;
BEGIN {
$CLASS = 'Mock::Quick::Method';
- use_ok( $CLASS );
+ use_ok($CLASS);
}
tests create => sub {
my $code = sub { 1 };
- my $obj = $CLASS->new( $code );
+ my $obj = $CLASS->new($code);
isa_ok( $obj, $CLASS );
+ is( $CLASS->new($code), $obj, "Building a method with the same sub twice succeeds" );
};
tests error => sub {
- throws_ok { $CLASS->new( "foo" ) }
- qr/Constructor to $CLASS takes a single codeblock/,
- "Must be created with codeblock"
+ throws_ok { $CLASS->new("foo") } qr/Constructor to $CLASS takes a single codeblock/, "Must be created with codeblock";
};
run_tests;
View
@@ -5,11 +5,19 @@ use warnings;
use Test::More;
BEGIN {
- require_ok( 'Object::Quick' );
+
+ $SIG{__WARN__} = sub {
+ my $msg = shift;
+ print STDERR $msg unless $msg =~ m/Object::Quick is depricated/;
+ };
+
+ warn "foo";
+
+ require_ok('Object::Quick');
Object::Quick->import();
ok( !__PACKAGE__->can($_), "$_ not imported" ) for qw/obj method clear/;
- Object::Quick->import( 'objx' );
+ Object::Quick->import('objx');
ok( !__PACKAGE__->can($_), "$_ not imported" ) for qw/obj method clear/;
can_ok( __PACKAGE__, 'objx' );
@@ -21,7 +29,7 @@ BEGIN {
ok( !__PACKAGE__->can($_), "$_ not imported" ) for qw/obj method clear/;
can_ok( __PACKAGE__, 'objz', 'vmz', 'clearz' );
- Object::Quick->import( '-obj' );
+ Object::Quick->import('-obj');
can_ok( __PACKAGE__, qw/obj method clear/ );
}

0 comments on commit 9cb6fa1

Please sign in to comment.