|
Revision 9731, 0.9 kB
(checked in by hanekomu, 5 years ago)
|
r6028@nbgr: marcel | 2008-04-18 16:09:30 +0200
lang/perl/Aspect: initial commit
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #! /usr/bin/perl -Tw |
|---|
| 2 | |
|---|
| 3 | package Test::Class::MethodInfo; |
|---|
| 4 | use 5.006; |
|---|
| 5 | use strict; |
|---|
| 6 | use warnings; |
|---|
| 7 | use Carp; |
|---|
| 8 | |
|---|
| 9 | our $VERSION = '0.01'; |
|---|
| 10 | |
|---|
| 11 | sub is_method_type { |
|---|
| 12 | my ($self, $type) = @_; |
|---|
| 13 | return($type =~ m/^(startup|setup|test|teardown|shutdown)$/s); |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| 16 | sub is_num_tests { |
|---|
| 17 | my ($self, $num_tests) = @_; |
|---|
| 18 | return($num_tests =~ m/^(no_plan)|(\+?\d+)$/s); |
|---|
| 19 | }; |
|---|
| 20 | |
|---|
| 21 | sub new { |
|---|
| 22 | my ($class, %param) = @_; |
|---|
| 23 | my $self = bless { |
|---|
| 24 | name => $param{name}, |
|---|
| 25 | type => $param{type} || 'test', |
|---|
| 26 | }, $class; |
|---|
| 27 | unless ( defined( $param{num_tests} ) ) { |
|---|
| 28 | $param{num_tests} = $self->is_type('test') ? 1 : 0; |
|---|
| 29 | }; |
|---|
| 30 | $self->num_tests( $param{num_tests} ); |
|---|
| 31 | return($self); |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | sub name { shift->{name} }; |
|---|
| 35 | |
|---|
| 36 | sub num_tests { |
|---|
| 37 | my ($self, $n) = @_; |
|---|
| 38 | if (defined($n)) { |
|---|
| 39 | croak "$n not valid number of tests" |
|---|
| 40 | unless $self->is_num_tests($n); |
|---|
| 41 | $self->{_num_tests} = $n; |
|---|
| 42 | }; |
|---|
| 43 | return($self->{_num_tests}); |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | sub is_type { |
|---|
| 47 | my ($self, $type) = @_; |
|---|
| 48 | $self->{type} eq $type; |
|---|
| 49 | }; |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | 1; |
|---|