| 1 | package Test::Class::Sugar; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use Devel::Declare (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use Devel::Declare::Context::Simple; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use B::Hooks::EndOfScope; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use Test::Class::Sugar::Context; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use Test::Class::Sugar::CodeGenerator; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use Carp qw/croak/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 2 | our $VERSION = '0.0400'; | |||||||||||
| 13 | |||||||||||||
| 14 | 2 | my %PARSER_FOR = ( | |||||||||||
| 15 | testclass => '_parse_testclass', | ||||||||||||
| 16 | startup => '_parse_inner_keyword', | ||||||||||||
| 17 | setup => '_parse_inner_keyword', | ||||||||||||
| 18 | test => '_parse_inner_keyword', | ||||||||||||
| 19 | teardown => '_parse_inner_keyword', | ||||||||||||
| 20 | shutdown => '_parse_inner_keyword', | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | 2 | ▶ | use Sub::Exporter -setup => { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | exports => [qw/testclass startup setup test teardown shutdown/], | ||||||||||||
| 25 | groups => {default => [qw/testclass/], | ||||||||||||
| 26 | inner => [qw/startup setup test teardown shutdown/]}, | ||||||||||||
| 27 | 15 | ▶ | installer => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||
| 28 | 15 | my ($args, $to_export) = @_; | |||||||||||
| 29 | 15 | my $pack = $args->{into}; | |||||||||||
| 30 | 15 | ▶ | unless (@$to_export) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 1 | unshift @$to_export, 'testclass', \&testclass; | |||||||||||
| 32 | } | ||||||||||||
| 33 | 15 | foreach my $name (@$to_export) { | |||||||||||
| 34 | 134 | ▶ | my $parser_called = defined $PARSER_FOR{$name} ? $PARSER_FOR{$name} : '-NOTHING-'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 134 | ▶ | if (my $parser = __PACKAGE__->can($parser_called)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | Devel::Declare->setup_for( | ||||||||||||
| 37 | $pack, | ||||||||||||
| 38 | 41 | ▶ | { $name => { const => sub { $parser->($pack, $args->{col}{defaults}, @_) } } }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 39 | 67 | ); | |||||||||||
| 40 | } | ||||||||||||
| 41 | } | ||||||||||||
| 42 | 15 | Sub::Exporter::default_installer(@_); | |||||||||||
| 43 | }, | ||||||||||||
| 44 | 2 | collectors => [qw/defaults/], | |||||||||||
| 45 | 2 | }; | |||||||||||
| 46 | |||||||||||||
| 47 | 28 | ▶ | sub _test_generator { | ||||||||||
|
Subroutine
_test_generator: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 28 | my($ctx, $name, $plan) = @_; | |||||||||||
| 49 | 28 | Test::Class::Sugar::CodeGenerator->new( | |||||||||||
| 50 | context => $ctx, | ||||||||||||
| 51 | name => $name, | ||||||||||||
| 52 | plan => $plan, | ||||||||||||
| 53 | ); | ||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 13 | ▶ | sub _testclass_generator { | ||||||||||
|
Subroutine
_testclass_generator: called CC=4 SCAR=13.9
| |||||||||||||
| 57 | 13 | my($ctx, $classname, $defaults, $options) = @_; | |||||||||||
| 58 | |||||||||||||
| 59 | 13 | foreach my $key (keys %$defaults) { | |||||||||||
| 60 | 1 | ▶ | defined $options->{$key} ? () : ($options->{$key} = $defaults->{$key}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 13 | my $ret = Test::Class::Sugar::CodeGenerator->new( | |||||||||||
| 64 | context => $ctx, | ||||||||||||
| 65 | options => $options, | ||||||||||||
| 66 | ); | ||||||||||||
| 67 | 13 | ▶ | $ret->classname($classname) if $classname; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 13 | return $ret; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | |||||||||||||
| 72 | 28 | ▶ | sub _parse_inner_keyword { | ||||||||||
|
Subroutine
_parse_inner_keyword: called CC=2 SCAR=6.9
| |||||||||||||
| 73 | 28 | my $pack = shift; | |||||||||||
| 74 | 28 | my $defaults = shift; | |||||||||||
| 75 | |||||||||||||
| 76 | 28 | local $Carp::Internal{'Devel::Declare'} = 1; | |||||||||||
| 77 | |||||||||||||
| 78 | 28 | my $ctx = Test::Class::Sugar::Context->new->init(@_); | |||||||||||
| 79 | 28 | my $preamble = ''; | |||||||||||
| 80 | |||||||||||||
| 81 | 28 | $ctx->skip_declarator; | |||||||||||
| 82 | |||||||||||||
| 83 | 28 | ▶ | my $name = $ctx->strip_test_name | ||||||||||
|
Condition50%1/2
$ctx->strip_test_name || croak(q[Can't make a test without a name])
MC/DC0%0/1
$ctx->strip_test_name || croak(q[Can't make a test without a name])
$ctx->strip_test_name
Truth table50%1/2
A
A= $ctx->strip_test_name
| |||||||||||||
| 84 | || croak "Can't make a test without a name"; | ||||||||||||
| 85 | 28 | my $plan = $ctx->strip_plan; | |||||||||||
| 86 | |||||||||||||
| 87 | 28 | _test_generator($ctx, $name, $plan)->install_test(); | |||||||||||
| 88 | |||||||||||||
| 89 | 28 | return; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 13 | ▶ | sub _parse_testclass { | ||||||||||
|
Subroutine
_parse_testclass: called CC=1 SCAR=0.0
| |||||||||||||
| 93 | 13 | my $pack = shift; | |||||||||||
| 94 | 13 | my $defaults = shift; | |||||||||||
| 95 | |||||||||||||
| 96 | 13 | local $Carp::Internal{'Devel::Declare'} = 1; | |||||||||||
| 97 | |||||||||||||
| 98 | 13 | my $ctx = Test::Class::Sugar::Context->new->init(@_); | |||||||||||
| 99 | |||||||||||||
| 100 | 13 | $ctx->skip_declarator; | |||||||||||
| 101 | 13 | my $classname = $ctx->strip_testclass_name; | |||||||||||
| 102 | 13 | _testclass_generator($ctx, $classname, $defaults, $ctx->strip_options) | |||||||||||
| 103 | ->install_testclass; | ||||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | sub testclass (&) {} | ||||||||||
|
Subroutine
testclass: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 107 | |||||||||||||
| 108 | 0 | ▶ | sub startup (&) {} | ||||||||||
|
Subroutine
startup: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 109 | 0 | ▶ | sub setup (&) {} | ||||||||||
|
Subroutine
setup: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 110 | 0 | ▶ | sub test (&) { croak "Should not be called" } | ||||||||||
|
Subroutine
test: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 111 | 0 | ▶ | sub teardown (&) {} | ||||||||||
|
Subroutine
teardown: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 112 | 0 | ▶ | sub shutdown (&) {} | ||||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 113 | |||||||||||||
| 114 | 2 | 1; | |||||||||||
| 115 | __END__ | ||||||||||||