| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::Run::CmdLine::Iface; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 90422 | use warnings; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 205 |  | 
| 4 | 6 |  |  | 6 |  | 29 | use strict; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 194 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 6 |  |  | 6 |  | 32 | use vars (qw($VERSION)); | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 429 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | $VERSION = '0.0131'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | extends ('Test::Run::Base'); | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 6 |  |  | 6 |  | 3534 | use UNIVERSAL::require; | 
|  | 6 |  |  |  |  | 7455 |  | 
|  | 6 |  |  |  |  | 67 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 6 |  |  | 6 |  | 3725 | use Test::Run::CmdLine; | 
|  | 6 |  |  |  |  | 20 |  | 
|  | 6 |  |  |  |  | 70 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 | 6 |  |  | 6 |  | 240 | use Moose; | 
|  | 6 |  |  |  |  | 12 |  | 
|  | 6 |  |  |  |  | 35 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 NAME | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | Test::Run::CmdLine::Iface - Analyze tests from the command line using Test::Run | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | use Test::Run::CmdLine::Iface; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my $tester = Test::Run::CmdLine::Iface->new( | 
| 27 |  |  |  |  |  |  | { | 
| 28 |  |  |  |  |  |  | 'test_files' => ["t/one.t", "t/two.t"], | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  | ); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | $tester->run(); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =cut | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | has 'driver_class' => (is => "rw", isa => "Str", init_arg => undef,); | 
| 37 |  |  |  |  |  |  | has 'driver_plugins' => (is => "rw", isa => "ArrayRef", | 
| 38 |  |  |  |  |  |  | default => sub { [] }, init_arg => undef,); | 
| 39 |  |  |  |  |  |  | has '_driver_class_arg' => (is => "ro", isa => "Str", init_arg => "driver_class"); | 
| 40 |  |  |  |  |  |  | has '_driver_plugins_arg' => (is => "ro", isa => "Maybe[ArrayRef]", init_arg => "driver_plugins"); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | has 'test_files' => (is => "rw", isa => "ArrayRef", default => sub { [] },); | 
| 43 |  |  |  |  |  |  | has 'backend_params' => (is => "rw", isa => "HashRef", predicate => "has_backend_params"); | 
| 44 |  |  |  |  |  |  | has '_is_driver_class_prepared' => (is => "rw", isa => "Bool", default => 0); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub BUILD | 
| 47 |  |  |  |  |  |  | { | 
| 48 | 10 |  |  | 10 | 1 | 21401 | my ($self) = @_; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 10 |  |  |  |  | 434 | my $driver_class = $self->_driver_class_arg() ; | 
| 51 | 10 |  |  |  |  | 403 | my $plugins = $self->_driver_plugins_arg(); | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 10 | 100 | 100 |  |  | 95 | if ($driver_class || $plugins) | 
|  |  | 100 | 66 |  |  |  |  | 
| 54 |  |  |  |  |  |  | { | 
| 55 | 5 |  | 100 |  |  | 56 | $self->_set_driver( | 
|  |  |  | 100 |  |  |  |  | 
| 56 |  |  |  |  |  |  | { | 
| 57 |  |  |  |  |  |  | 'class' => ($driver_class || | 
| 58 |  |  |  |  |  |  | "Test::Run::CmdLine::Drivers::Default"), | 
| 59 |  |  |  |  |  |  | 'plugins' => ($plugins || []), | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | ); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  | elsif ($ENV{'HARNESS_DRIVER'} || $ENV{'HARNESS_PLUGINS'}) | 
| 64 |  |  |  |  |  |  | { | 
| 65 |  |  |  |  |  |  | $self->_set_driver( | 
| 66 |  |  |  |  |  |  | { | 
| 67 |  |  |  |  |  |  | 'class' => ($ENV{'HARNESS_DRIVER'} || | 
| 68 |  |  |  |  |  |  | "Test::Run::CmdLine::Drivers::Default"), | 
| 69 | 1 |  | 50 |  |  | 13 | 'plugins' => [split(/\s+/, $ENV{'HARNESS_PLUGINS'} || "")] | 
|  |  |  | 50 |  |  |  |  | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  | ); | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  | else | 
| 74 |  |  |  |  |  |  | { | 
| 75 | 4 |  |  |  |  | 25 | $self->_set_driver( | 
| 76 |  |  |  |  |  |  | { | 
| 77 |  |  |  |  |  |  | 'class' => "Test::Run::CmdLine::Drivers::Default", | 
| 78 |  |  |  |  |  |  | 'plugins' => [], | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | ); | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 10 |  |  |  |  | 44 | return; | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head1 Interface Functions | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =head2 $tester = Test::Run::CmdLine::Iface->new({'test_files' => \@test_files, ....}); | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | Initializes a new testing front end. C<test_files> is a named argument that | 
| 91 |  |  |  |  |  |  | contains the files to test. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | Other named arguments are: | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =over 4 | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =item backend_params | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | This is a hash of named parameters to be passed to the backend class (derived | 
| 100 |  |  |  |  |  |  | from L<Test::Run::Obj>.) | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =item driver_class | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | This is the backend class that will be instantiated and used to perform | 
| 105 |  |  |  |  |  |  | the processing. Defaults to L<Test::Run::CmdLine::Drivers::Default>. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =item driver_plugins | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | This is a list of plugin classes to be used by the driver class. Each plugin | 
| 110 |  |  |  |  |  |  | is a module and a corresponding class, that is prefixed by | 
| 111 |  |  |  |  |  |  | C<Test::Run::CmdLine::Plugin::> - a prefix which should not be included in | 
| 112 |  |  |  |  |  |  | them. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =back | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head2 $tester->run() | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Actually runs the tests on the command line. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =head2 BUILD | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | For Moose. | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | TODO : Write more. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =cut | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | sub _real_prepare_driver_class | 
| 129 |  |  |  |  |  |  | { | 
| 130 | 6 |  |  | 6 |  | 15 | my $self = shift; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 6 |  |  |  |  | 237 | my $driver_class = $self->driver_class(); | 
| 133 | 6 |  |  |  |  | 70 | $driver_class->require(); | 
| 134 | 6 | 50 |  |  |  | 45721 | if ($@) | 
| 135 |  |  |  |  |  |  | { | 
| 136 | 0 |  |  |  |  | 0 | die $@; | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 6 |  |  |  |  | 14 | foreach my $plugin (@{$self->_calc_plugins_for_ISA()}) | 
|  | 6 |  |  |  |  | 28 |  | 
| 140 |  |  |  |  |  |  | { | 
| 141 | 8 |  |  |  |  | 87 | $plugin->require(); | 
| 142 | 8 | 50 |  |  |  | 28147 | if ($@) | 
| 143 |  |  |  |  |  |  | { | 
| 144 | 0 |  |  |  |  | 0 | die $@; | 
| 145 |  |  |  |  |  |  | } | 
| 146 |  |  |  |  |  |  | { | 
| 147 | 6 |  |  | 6 |  | 40675 | no strict 'refs'; | 
|  | 6 |  |  |  |  | 13 |  | 
|  | 6 |  |  |  |  | 409 |  | 
|  | 8 |  |  |  |  | 16 |  | 
| 148 | 8 |  |  |  |  | 15 | push @{"${driver_class}::ISA"}, $plugin; | 
|  | 8 |  |  |  |  | 190 |  | 
| 149 |  |  |  |  |  |  | } | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | # Finally - put Test::Run::CmdLine there. | 
| 153 |  |  |  |  |  |  | { | 
| 154 | 6 |  |  | 6 |  | 54 | no strict 'refs'; | 
|  | 6 |  |  |  |  | 13 |  | 
|  | 6 |  |  |  |  | 3522 |  | 
|  | 6 |  |  |  |  | 19 |  | 
| 155 | 6 |  |  |  |  | 14 | push @{"${driver_class}::ISA"}, "Test::Run::CmdLine"; | 
|  | 6 |  |  |  |  | 120 |  | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | } | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | # Does _real_prepare_driver_class with memoization. | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | sub _prepare_driver_class | 
| 164 |  |  |  |  |  |  | { | 
| 165 | 6 |  |  | 6 |  | 11 | my $self = shift; | 
| 166 |  |  |  |  |  |  |  | 
| 167 | 6 | 50 |  |  |  | 284 | if (! $self->_is_driver_class_prepared()) | 
| 168 |  |  |  |  |  |  | { | 
| 169 | 6 |  |  |  |  | 24 | $self->_real_prepare_driver_class(); | 
| 170 |  |  |  |  |  |  |  | 
| 171 | 6 |  |  |  |  | 302 | $self->_is_driver_class_prepared(1); | 
| 172 |  |  |  |  |  |  | } | 
| 173 | 6 |  |  |  |  | 17 | return; | 
| 174 |  |  |  |  |  |  | } | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | sub _calc_driver | 
| 177 |  |  |  |  |  |  | { | 
| 178 | 6 |  |  | 6 |  | 44 | my $self = shift; | 
| 179 |  |  |  |  |  |  |  | 
| 180 | 6 |  |  |  |  | 20 | $self->_prepare_driver_class(); | 
| 181 |  |  |  |  |  |  |  | 
| 182 | 6 | 50 |  |  |  | 257 | my $driver = $self->driver_class()->new( | 
| 183 |  |  |  |  |  |  | { | 
| 184 |  |  |  |  |  |  | 'test_files' => $self->test_files(), | 
| 185 |  |  |  |  |  |  | ($self->has_backend_params() | 
| 186 |  |  |  |  |  |  | ? ('backend_params' => $self->backend_params()) | 
| 187 |  |  |  |  |  |  | : () | 
| 188 |  |  |  |  |  |  | ), | 
| 189 |  |  |  |  |  |  | } | 
| 190 |  |  |  |  |  |  | ); | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | } | 
| 193 |  |  |  |  |  |  | sub run | 
| 194 |  |  |  |  |  |  | { | 
| 195 | 3 |  |  | 3 | 1 | 1845 | my $self = shift; | 
| 196 |  |  |  |  |  |  |  | 
| 197 | 3 |  |  |  |  | 11 | return $self->_calc_driver()->run(); | 
| 198 |  |  |  |  |  |  | } | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | sub _check_driver_class | 
| 201 |  |  |  |  |  |  | { | 
| 202 | 10 |  |  | 10 |  | 19 | my $self = shift; | 
| 203 | 10 |  |  |  |  | 42 | return $self->_is_class_name(@_); | 
| 204 |  |  |  |  |  |  | } | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | sub _check_plugins | 
| 207 |  |  |  |  |  |  | { | 
| 208 | 10 |  |  | 10 |  | 29 | my $self = shift; | 
| 209 | 10 |  |  |  |  | 17 | my $plugins = shift; | 
| 210 | 10 |  |  |  |  | 26 | foreach my $p (@$plugins) | 
| 211 |  |  |  |  |  |  | { | 
| 212 | 8 | 50 |  |  |  | 23 | if (! $self->_is_class_name($p)) | 
| 213 |  |  |  |  |  |  | { | 
| 214 | 0 |  |  |  |  | 0 | return 0; | 
| 215 |  |  |  |  |  |  | } | 
| 216 |  |  |  |  |  |  | } | 
| 217 | 10 |  |  |  |  | 34 | return 1; | 
| 218 |  |  |  |  |  |  | } | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | sub _is_class_name | 
| 221 |  |  |  |  |  |  | { | 
| 222 | 22 |  |  | 22 |  | 44 | my $self = shift; | 
| 223 | 22 |  |  |  |  | 36 | my $class = shift; | 
| 224 | 22 |  |  |  |  | 164 | return ($class =~ /^\w+(?:::\w+)*$/); | 
| 225 |  |  |  |  |  |  | } | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | sub _set_driver | 
| 228 |  |  |  |  |  |  | { | 
| 229 | 10 |  |  | 10 |  | 22 | my ($self, $args) = @_; | 
| 230 |  |  |  |  |  |  |  | 
| 231 | 10 |  |  |  |  | 23 | my $class = $args->{'class'}; | 
| 232 | 10 | 50 |  |  |  | 33 | if (! $self->_check_driver_class($class)) | 
| 233 |  |  |  |  |  |  | { | 
| 234 | 0 |  |  |  |  | 0 | die "Invalid Driver Class \"$class\"!"; | 
| 235 |  |  |  |  |  |  | } | 
| 236 | 10 |  |  |  |  | 402 | $self->driver_class($class); | 
| 237 |  |  |  |  |  |  |  | 
| 238 | 10 |  |  |  |  | 29 | my $plugins = $args->{'plugins'}; | 
| 239 | 10 | 50 |  |  |  | 32 | if (! $self->_check_plugins($plugins)) | 
| 240 |  |  |  |  |  |  | { | 
| 241 | 0 |  |  |  |  | 0 | die "Invalid Plugins for Test::Run::CmdLine::Iface!"; | 
| 242 |  |  |  |  |  |  | } | 
| 243 | 10 |  |  |  |  | 409 | $self->driver_plugins($plugins); | 
| 244 |  |  |  |  |  |  |  | 
| 245 | 10 |  |  |  |  | 21 | return 0; | 
| 246 |  |  |  |  |  |  | } | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | sub _calc_plugins_for_ISA | 
| 249 |  |  |  |  |  |  | { | 
| 250 | 6 |  |  | 6 |  | 16 | my $self = shift; | 
| 251 |  |  |  |  |  |  | return | 
| 252 |  |  |  |  |  |  | [ | 
| 253 | 8 |  |  |  |  | 31 | map { $self->_calc_single_plugin_for_ISA($_) } | 
| 254 | 6 |  |  |  |  | 12 | @{$self->driver_plugins()} | 
|  | 6 |  |  |  |  | 258 |  | 
| 255 |  |  |  |  |  |  | ]; | 
| 256 |  |  |  |  |  |  | } | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | sub _calc_single_plugin_for_ISA | 
| 259 |  |  |  |  |  |  | { | 
| 260 | 8 |  |  | 8 |  | 15 | my $self = shift; | 
| 261 | 8 |  |  |  |  | 17 | my $p = shift; | 
| 262 |  |  |  |  |  |  |  | 
| 263 | 8 |  |  |  |  | 41 | return "Test::Run::CmdLine::Plugin::$p"; | 
| 264 |  |  |  |  |  |  | } | 
| 265 |  |  |  |  |  |  |  | 
| 266 |  |  |  |  |  |  | =head1 AUTHOR | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  | Shlomi Fish, L<http://www.shlomifish.org/> . | 
| 269 |  |  |  |  |  |  |  | 
| 270 |  |  |  |  |  |  | =head1 BUGS | 
| 271 |  |  |  |  |  |  |  | 
| 272 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 273 |  |  |  |  |  |  | C<bug-test-run-cmdline@rt.cpan.org>, or through the web interface at | 
| 274 |  |  |  |  |  |  | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Run-CmdLine>. | 
| 275 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 276 |  |  |  |  |  |  | your bug as I make changes. | 
| 277 |  |  |  |  |  |  |  | 
| 278 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 279 |  |  |  |  |  |  |  | 
| 280 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 281 |  |  |  |  |  |  |  | 
| 282 |  |  |  |  |  |  | Copyright 2005 Shlomi Fish, all rights reserved. | 
| 283 |  |  |  |  |  |  |  | 
| 284 |  |  |  |  |  |  | This program is released under the MIT X11 License. | 
| 285 |  |  |  |  |  |  |  | 
| 286 |  |  |  |  |  |  | =cut | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | 1; # End of Test::Run::CmdLine |