| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Moose; | 
| 2 |  |  |  |  |  |  | our $VERSION = '2.2206'; | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 35 |  |  | 35 |  | 2438740 | use strict; | 
|  | 35 |  |  |  |  | 368 |  | 
|  | 35 |  |  |  |  | 1104 |  | 
| 5 | 35 |  |  | 35 |  | 205 | use warnings; | 
|  | 35 |  |  |  |  | 76 |  | 
|  | 35 |  |  |  |  | 962 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 35 |  |  | 35 |  | 19695 | use Sub::Exporter; | 
|  | 35 |  |  |  |  | 409394 |  | 
|  | 35 |  |  |  |  | 238 |  | 
| 8 | 35 |  |  | 35 |  | 8030 | use Test::Builder; | 
|  | 35 |  |  |  |  | 98 |  | 
|  | 35 |  |  |  |  | 1042 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 35 |  |  | 35 |  | 202 | use List::Util 1.33 'all'; | 
|  | 35 |  |  |  |  | 732 |  | 
|  | 35 |  |  |  |  | 3795 |  | 
| 11 | 35 |  |  | 35 |  | 15263 | use Moose::Util 'does_role', 'find_meta'; | 
|  | 35 |  |  |  |  | 152 |  | 
|  | 35 |  |  |  |  | 1798 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | my @exports = qw[ | 
| 14 |  |  |  |  |  |  | meta_ok | 
| 15 |  |  |  |  |  |  | does_ok | 
| 16 |  |  |  |  |  |  | has_attribute_ok | 
| 17 |  |  |  |  |  |  | with_immutable | 
| 18 |  |  |  |  |  |  | ]; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | Sub::Exporter::setup_exporter({ | 
| 21 |  |  |  |  |  |  | exports => \@exports, | 
| 22 |  |  |  |  |  |  | groups  => { default => \@exports } | 
| 23 |  |  |  |  |  |  | }); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | ## the test builder instance ... | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | my $Test = Test::Builder->new; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | ## exported functions | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub meta_ok ($;$) { | 
| 32 | 2 |  |  | 2 | 1 | 2707 | my ($class_or_obj, $message) = @_; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 2 |  | 50 |  |  | 8 | $message ||= "The object has a meta"; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 2 | 100 |  |  |  | 10 | if (find_meta($class_or_obj)) { | 
| 37 | 1 |  |  |  |  | 8 | return $Test->ok(1, $message) | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | else { | 
| 40 | 1 |  |  |  |  | 5 | return $Test->ok(0, $message); | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub does_ok ($$;$) { | 
| 45 | 61 |  |  | 61 | 1 | 6423 | my ($class_or_obj, $does, $message) = @_; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 61 |  | 66 |  |  | 346 | $message ||= "The object does $does"; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 61 | 100 |  |  |  | 223 | if (does_role($class_or_obj, $does)) { | 
| 50 | 54 |  |  |  |  | 248 | return $Test->ok(1, $message) | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | else { | 
| 53 | 7 |  |  |  |  | 26 | return $Test->ok(0, $message); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub has_attribute_ok ($$;$) { | 
| 58 | 4 |  |  | 4 | 1 | 3898 | my ($class_or_obj, $attr_name, $message) = @_; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 4 |  | 33 |  |  | 11 | $message ||= "The object does has an attribute named $attr_name"; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 4 |  |  |  |  | 15 | my $meta = find_meta($class_or_obj); | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 4 | 100 |  |  |  | 26 | if ($meta->find_attribute_by_name($attr_name)) { | 
| 65 | 3 |  |  |  |  | 15 | return $Test->ok(1, $message) | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | else { | 
| 68 | 1 |  |  |  |  | 4 | return $Test->ok(0, $message); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub with_immutable (&@) { | 
| 73 | 58 |  |  | 58 | 1 | 260505 | my $block = shift; | 
| 74 | 58 |  |  |  |  | 327 | my $before = $Test->current_test; | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 58 |  |  |  |  | 9413 | $block->(0); | 
| 77 | 58 |  |  |  |  | 6828 | Class::MOP::class_of($_)->make_immutable for @_; | 
| 78 | 58 |  |  |  |  | 315 | $block->(1); | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 58 |  |  |  |  | 6605 | my $num_tests = $Test->current_test - $before; | 
| 81 | 58 |  |  | 4036 |  | 8664 | my $all_passed = all { $_ } ($Test->summary)[-$num_tests..-1]; | 
|  | 4036 |  |  |  |  | 32750 |  | 
| 82 | 58 |  |  |  |  | 1023 | return $all_passed; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | 1; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | # ABSTRACT: Test functions for Moose specific features | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | __END__ | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =pod | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =encoding UTF-8 | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 NAME | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Test::Moose - Test functions for Moose specific features | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 VERSION | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | version 2.2206 | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | use Test::More plan => 1; | 
| 106 |  |  |  |  |  |  | use Test::Moose; | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | meta_ok($class_or_obj, "... Foo has a ->meta"); | 
| 109 |  |  |  |  |  |  | does_ok($class_or_obj, $role, "... Foo does the Baz role"); | 
| 110 |  |  |  |  |  |  | has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute"); | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | This module provides some useful test functions for Moose based classes. It | 
| 115 |  |  |  |  |  |  | is an experimental first release, so comments and suggestions are very welcome. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 EXPORTED FUNCTIONS | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head2 meta_ok ($class_or_object) | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Tests if a class or object has a metaclass. | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head2 does_ok ($class_or_object, $role, ?$message) | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | Tests if a class or object does a certain role, similar to what C<isa_ok> | 
| 126 |  |  |  |  |  |  | does for the C<isa> method. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head2 has_attribute_ok($class_or_object, $attr_name, ?$message) | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | Tests if a class or object has a certain attribute, similar to what C<can_ok> | 
| 131 |  |  |  |  |  |  | does for the methods. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head2 with_immutable { CODE } @class_names | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | Runs B<CODE> (which should contain normal tests) twice, and make each | 
| 136 |  |  |  |  |  |  | class in C<@class_names> immutable in between the two runs. | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | The B<CODE> block is called with a single boolean argument indicating whether | 
| 139 |  |  |  |  |  |  | or not the classes have been made immutable yet. | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head1 TODO | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =over 4 | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item Convert the Moose test suite to use this module. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =item Here is a list of possible functions to write | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =over 4 | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =item immutability predicates | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item anon-class predicates | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =item discovering original method from modified method | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =item attribute metaclass predicates (attribute_isa?) | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =back | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | =back | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | =over 4 | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =item L<Test::More> | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | =back | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =head1 BUGS | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | See L<Moose/BUGS> for details on reporting bugs. | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =head1 AUTHORS | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =over 4 | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =item * | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | Stevan Little <stevan@cpan.org> | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =item * | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Dave Rolsky <autarch@urth.org> | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =item * | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | Jesse Luehrs <doy@cpan.org> | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | =item * | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | Shawn M Moore <sartak@cpan.org> | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =item * | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =item * | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | Karen Etheridge <ether@cpan.org> | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =item * | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | Florian Ragwitz <rafl@debian.org> | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | =item * | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | Hans Dieter Pearcey <hdp@cpan.org> | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =item * | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | Chris Prather <chris@prather.org> | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | =item * | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | Matt S Trout <mstrout@cpan.org> | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | =back | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | This software is copyright (c) 2006 by Infinity Interactive, Inc. | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 226 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | =cut |