| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Mouse; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 26 |  |  | 26 |  | 343839 | use Mouse::Exporter; | 
|  | 26 |  |  |  |  | 49 |  | 
|  | 26 |  |  |  |  | 150 |  | 
| 4 | 26 |  |  | 26 |  | 110 | use Mouse::Util qw(does_role find_meta); | 
|  | 26 |  |  |  |  | 30 |  | 
|  | 26 |  |  |  |  | 103 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 26 |  |  | 26 |  | 102 | use Test::Builder; | 
|  | 26 |  |  |  |  | 31 |  | 
|  | 26 |  |  |  |  | 7780 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | my $Test = Test::Builder->new; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | ## exported functions | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub meta_ok ($;$) { ## no critic | 
| 24 | 2 |  |  | 2 | 1 | 612 | my ($class_or_obj, $message) = @_; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 2 |  | 50 |  |  | 6 | $message ||= "The object has a meta"; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 2 | 100 |  |  |  | 7 | if (find_meta($class_or_obj)) { | 
| 29 | 1 |  |  |  |  | 5 | return $Test->ok(1, $message) | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | else { | 
| 32 | 1 |  |  |  |  | 3 | return $Test->ok(0, $message); | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub does_ok ($$;$) { ## no critic | 
| 37 | 22 |  |  | 22 | 1 | 2542 | my ($class_or_obj, $does, $message) = @_; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 22 |  | 66 |  |  | 92 | $message ||= "The object does $does"; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 22 | 100 |  |  |  | 50 | if (does_role($class_or_obj, $does)) { | 
| 42 | 20 |  |  |  |  | 58 | return $Test->ok(1, $message) | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | else { | 
| 45 | 2 |  |  |  |  | 6 | return $Test->ok(0, $message); | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub has_attribute_ok ($$;$) { ## no critic | 
| 50 | 10 |  |  | 10 | 1 | 3703 | my ($class_or_obj, $attr_name, $message) = @_; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 10 |  | 66 |  |  | 38 | $message ||= "The object does has an attribute named $attr_name"; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 10 |  |  |  |  | 23 | my $meta = find_meta($class_or_obj); | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 10 | 100 |  |  |  | 27 | if ($meta->find_attribute_by_name($attr_name)) { | 
| 57 | 9 |  |  |  |  | 20 | return $Test->ok(1, $message) | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | else { | 
| 60 | 1 |  |  |  |  | 9 | return $Test->ok(0, $message); | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub with_immutable (&@) { ## no critic | 
| 65 | 20 |  |  | 20 | 1 | 3820 | my $block = shift; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 20 |  |  |  |  | 95 | my $before = $Test->current_test; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 20 |  |  |  |  | 195 | $block->(); | 
| 70 | 20 |  |  |  |  | 32650 | $_->meta->make_immutable for @_; | 
| 71 | 20 |  |  |  |  | 56 | $block->(); | 
| 72 | 20 | 100 |  |  |  | 34780 | return if not defined wantarray; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 2 |  |  |  |  | 6 | my $num_tests = $Test->current_test - $before; | 
| 75 | 2 |  |  |  |  | 15 | return !grep{ !$_ } ($Test->summary)[-$num_tests .. -1]; | 
|  | 4 |  |  |  |  | 20 |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | 1; | 
| 79 |  |  |  |  |  |  | __END__ |