1package Test::Object::Test; 2 3use strict; 4use Carp (); 5use Scalar::Util (); 6 7our $VERSION = '0.08'; 8 9 10 11 12 13##################################################################### 14# Constructor and Accessors 15 16sub new { 17 my $class = shift; 18 my $self = bless { @_ }, $class; 19 20 # Check params 21 unless ( _CLASS($self->class) ) { 22 Carp::croak("Did not provide a valid test class"); 23 } 24 unless ( _CODELIKE($self->code) ) { 25 Carp::croak("Did not provide a valid CODE or callable object"); 26 } 27 28 $self; 29} 30 31sub class { 32 $_[0]->{class}; 33} 34 35sub tests { 36 $_[0]->{tests}; 37} 38 39sub code { 40 $_[0]->{code}; 41} 42 43 44 45 46 47##################################################################### 48# Main Methods 49 50sub run { 51 $_[0]->code->( $_[1] ); 52} 53 54 55 56 57 58##################################################################### 59# Support Functions 60 61# Stolen from Params::Util to avoid adding a dependency needlessly 62 63sub _CLASS ($) { 64 (defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s) ? $_[0] : undef; 65} 66 67sub _CODELIKE { 68 (Scalar::Util::reftype($_[0])||'') eq 'CODE' 69 or 70 Scalar::Util::blessed($_[0]) and overload::Method($_[0],'&{}') 71 ? $_[0] : undef; 72} 73 741; 75