| 1 | package Test::Mouse; | ||||||||||||
| 2 | |||||||||||||
| 3 | 26 | ▶ | use Mouse::Exporter; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 26 | ▶ | use Mouse::Util qw(does_role find_meta); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 26 | ▶ | use Test::Builder; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 26 | Mouse::Exporter->setup_import_methods( | |||||||||||
| 9 | as_is => [qw( | ||||||||||||
| 10 | meta_ok | ||||||||||||
| 11 | does_ok | ||||||||||||
| 12 | has_attribute_ok | ||||||||||||
| 13 | with_immutable | ||||||||||||
| 14 | )], | ||||||||||||
| 15 | ); | ||||||||||||
| 16 | |||||||||||||
| 17 | ## the test builder instance ... | ||||||||||||
| 18 | |||||||||||||
| 19 | 26 | my $Test = Test::Builder->new; | |||||||||||
| 20 | |||||||||||||
| 21 | ## exported functions | ||||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | sub meta_ok ($;$) { ## no critic | ||||||||||
|
Subroutine
meta_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 24 | 2 | my ($class_or_obj, $message) = @_; | |||||||||||
| 25 | |||||||||||||
| 26 | 2 | ▶ | $message ||= "The object has a meta"; | ||||||||||
|
Condition50%1/2
$message ||= "The object has a meta"
MC/DC0%0/1
$message ||= "The object has a meta"
$message
Truth table50%1/2
A
A= $message
| |||||||||||||
| 27 | |||||||||||||
| 28 | 2 | ▶ | if (find_meta($class_or_obj)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 1 | return $Test->ok(1, $message) | |||||||||||
| 30 | } | ||||||||||||
| 31 | else { | ||||||||||||
| 32 | 1 | return $Test->ok(0, $message); | |||||||||||
| 33 | } | ||||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 22 | ▶ | sub does_ok ($$;$) { ## no critic | ||||||||||
|
Subroutine
does_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 37 | 22 | my ($class_or_obj, $does, $message) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 22 | ▶ | $message ||= "The object does $does"; | ||||||||||
|
Condition100%2/2
$message ||= "The object does $does"
MC/DC100%1/1
$message ||= "The object does $does"
$message
Truth table100%2/2
A
A= $message
| |||||||||||||
| 40 | |||||||||||||
| 41 | 22 | ▶ | if (does_role($class_or_obj, $does)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 20 | return $Test->ok(1, $message) | |||||||||||
| 43 | } | ||||||||||||
| 44 | else { | ||||||||||||
| 45 | 2 | return $Test->ok(0, $message); | |||||||||||
| 46 | } | ||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 10 | ▶ | sub has_attribute_ok ($$;$) { ## no critic | ||||||||||
|
Subroutine
has_attribute_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 50 | 10 | my ($class_or_obj, $attr_name, $message) = @_; | |||||||||||
| 51 | |||||||||||||
| 52 | 10 | ▶ | $message ||= "The object does has an attribute named $attr_name"; | ||||||||||
|
Condition100%2/2
$message ||= "The object does has an attribute named $attr_name"
MC/DC100%1/1
$message ||= "The object does has an attribute named $attr_name"
$message
Truth table100%2/2
A
A= $message
| |||||||||||||
| 53 | |||||||||||||
| 54 | 10 | my $meta = find_meta($class_or_obj); | |||||||||||
| 55 | |||||||||||||
| 56 | 10 | ▶ | if ($meta->find_attribute_by_name($attr_name)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | 9 | return $Test->ok(1, $message) | |||||||||||
| 58 | } | ||||||||||||
| 59 | else { | ||||||||||||
| 60 | 1 | return $Test->ok(0, $message); | |||||||||||
| 61 | } | ||||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 20 | ▶ | sub with_immutable (&@) { ## no critic | ||||||||||
|
Subroutine
with_immutable: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 65 | 20 | my $block = shift; | |||||||||||
| 66 | |||||||||||||
| 67 | 20 | my $before = $Test->current_test; | |||||||||||
| 68 | |||||||||||||
| 69 | 20 | $block->(); | |||||||||||
| 70 | 20 | $_->meta->make_immutable for @_; | |||||||||||
| 71 | 20 | $block->(); | |||||||||||
| 72 | 20 | ▶ | return if not defined wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | |||||||||||||
| 74 | 2 | my $num_tests = $Test->current_test - $before; | |||||||||||
| 75 | 2 | return !grep{ !$_ } ($Test->summary)[-$num_tests .. -1]; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 26 | 1; | |||||||||||
| 79 | __END__ | ||||||||||||