| 1 | package Test::Class::Moose::Report; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Test information for Test::Class::Moose | ||||||||||
| 4 | |||||||||||
| 5 | 30 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 30 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 30 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 30 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 30 | our $VERSION = '1.00'; | |||||||||
| 12 | |||||||||||
| 13 | 30 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 30 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 30 | with 'Test::Class::Moose::Role::HasTimeReport'; | |||||||||
| 16 | |||||||||||
| 17 | 30 | ▶ | use List::Util qw( first sum0 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | has test_classes => ( | ||||||||||
| 20 | is => 'ro', | ||||||||||
| 21 | traits => ['Array'], | ||||||||||
| 22 | isa => 'ArrayRef[Test::Class::Moose::Report::Class]', | ||||||||||
| 23 | 35 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 30 | handles => { | |||||||||
| 25 | _all_test_classes => 'elements', | ||||||||||
| 26 | add_test_class => 'push', | ||||||||||
| 27 | num_test_classes => 'count', | ||||||||||
| 28 | }, | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | 8 | ▶ | sub num_test_instances { | ||||||||
|
Subroutine
num_test_instances: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 8 | my $self = shift; | |||||||||
| 33 | 8 | return sum0 map { $_->num_test_instances } $self->all_test_classes; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 8 | ▶ | sub num_test_methods { | ||||||||
|
Subroutine
num_test_methods: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | 8 | my $self = shift; | |||||||||
| 38 | 54 | return scalar grep { !$_->is_skipped } | |||||||||
| 39 | 24 | map { $_->all_test_methods } | |||||||||
| 40 | 8 | map { $_->all_test_instances } $self->all_test_classes; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 9 | ▶ | sub num_tests_run { | ||||||||
|
Subroutine
num_tests_run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 44 | 9 | my $self = shift; | |||||||||
| 45 | 51 | return sum0 map { $_->num_tests_run } | |||||||||
| 46 | 54 | grep { !$_->is_skipped } | |||||||||
| 47 | 25 | map { $_->all_test_methods } | |||||||||
| 48 | 9 | map { $_->all_test_instances } $self->all_test_classes; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 39 | ▶ | sub all_test_classes { | ||||||||
|
Subroutine
all_test_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 39 | my $self = shift; | |||||||||
| 53 | 39 | return $self->_all_test_classes; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 153 | ▶ | sub current_class { | ||||||||
|
Subroutine
current_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 153 | my $self = shift; | |||||||||
| 58 | 153 | return $self->test_classes->[-1]; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 153 | ▶ | sub current_instance { | ||||||||
|
Subroutine
current_instance: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 62 | 153 | my $self = shift; | |||||||||
| 63 | 153 | ▶ | my $current_class = $self->current_class or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 153 | return $current_class->current_instance; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 87 | ▶ | sub current_method { | ||||||||
|
Subroutine
current_method: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 68 | 87 | my $self = shift; | |||||||||
| 69 | 87 | ▶ | my $current_instance = $self->current_instance or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 87 | return $current_instance->current_method; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 13 | ▶ | sub plan { | ||||||||
|
Subroutine
plan: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 74 | 13 | my ( $self, $plan ) = @_; | |||||||||
| 75 | 13 | ▶ | my $current_method = $self->current_method | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | or croak(q{You tried to plan but we don't have a test method yet!}); | ||||||||||
| 77 | 13 | $current_method->plan($plan); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 6 | ▶ | sub timing_data { | ||||||||
|
Subroutine
timing_data: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 81 | 6 | my $self = shift; | |||||||||
| 82 | |||||||||||
| 83 | 6 | my %t = ( time => $self->time->as_hashref ); | |||||||||
| 84 | |||||||||||
| 85 | 6 | for my $class ( $self->all_test_classes ) { | |||||||||
| 86 | 20 | my $class_inner = $t{class}{ $class->name } | |||||||||
| 87 | = { time => $class->time->as_hashref }; | ||||||||||
| 88 | |||||||||||
| 89 | 20 | for my $instance ( $class->all_test_instances ) { | |||||||||
| 90 | 20 | my $instance_inner = $class_inner->{instance}{ $instance->name } | |||||||||
| 91 | = { time => $instance->time->as_hashref }; | ||||||||||
| 92 | |||||||||||
| 93 | 20 | $self->_populate_control_timing_data( | |||||||||
| 94 | $instance_inner, $instance, | ||||||||||
| 95 | qw( test_startup test_shutdown ) | ||||||||||
| 96 | ); | ||||||||||
| 97 | |||||||||||
| 98 | 20 | for my $method ( $instance->all_test_methods ) { | |||||||||
| 99 | 45 | my $method_inner = $instance_inner->{method}{ $method->name } | |||||||||
| 100 | = { time => $method->time->as_hashref }; | ||||||||||
| 101 | |||||||||||
| 102 | 45 | $self->_populate_control_timing_data( | |||||||||
| 103 | $method_inner, $method, | ||||||||||
| 104 | qw( test_setup test_teardown ), | ||||||||||
| 105 | ); | ||||||||||
| 106 | } | ||||||||||
| 107 | } | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 6 | return \%t; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 65 | ▶ | sub _populate_control_timing_data { | ||||||||
|
Subroutine
_populate_control_timing_data: called CC=3 SCAR=11.0
| |||||||||||
| 114 | 65 | my $self = shift; | |||||||||
| 115 | 65 | my $hashref = shift; | |||||||||
| 116 | 65 | my $report = shift; | |||||||||
| 117 | |||||||||||
| 118 | 65 | for my $control (@_) { | |||||||||
| 119 | 130 | ▶ | my $control_method = $report->${ \( $control . '_method' ) } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | or next; | ||||||||||
| 121 | $hashref->{control}{$control}{time} | ||||||||||
| 122 | 126 | = $control_method->time->as_hashref; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 65 | return; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 30 | __PACKAGE__->meta->make_immutable; | |||||||||
| 129 | |||||||||||
| 130 | 30 | 1; | |||||||||
| 131 | |||||||||||
| 132 | __END__ | ||||||||||