File: Test.pm

package info (click to toggle)
libtest-object-perl 0.08-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 297; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package Test::Object::Test;

use strict;
use Carp         ();
use Scalar::Util ();

our $VERSION = '0.08';





#####################################################################
# Constructor and Accessors

sub new {
	my $class = shift;
	my $self  = bless { @_ }, $class;

	# Check params
	unless ( _CLASS($self->class) ) {
		Carp::croak("Did not provide a valid test class");
	}
	unless ( _CODELIKE($self->code) ) {
		Carp::croak("Did not provide a valid CODE or callable object");
	}

	$self;
}

sub class {
	$_[0]->{class};
}

sub tests {
	$_[0]->{tests};
}

sub code {
	$_[0]->{code};
}





#####################################################################
# Main Methods

sub run {
	$_[0]->code->( $_[1] );
}





#####################################################################
# Support Functions

# Stolen from Params::Util to avoid adding a dependency needlessly

sub _CLASS ($) {
	(defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s) ? $_[0] : undef;
}

sub _CODELIKE {
	(Scalar::Util::reftype($_[0])||'') eq 'CODE'
	or
	Scalar::Util::blessed($_[0]) and overload::Method($_[0],'&{}')
	? $_[0] : undef;
}

1;