| 1 | package Test::Sweet::Keyword::Test; | ||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | $Test::Sweet::Keyword::Test::VERSION = '0.03'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | # ABSTRACT: provides the C<test> keyword | ||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | ▶ | use Devel::Declare (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use Sub::Name; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | use base 'Devel::Declare::Context::Simple'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 6 | ▶ | sub install_methodhandler { | ||||||||||
|
Subroutine
install_methodhandler: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 15 | 6 | my $class = shift; | |||||||||||
| 16 | 6 | my %args = @_; | |||||||||||
| 17 | { | ||||||||||||
| 18 | 3 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 6 | ▶ | *{$args{into}.'::test'} = sub (&) {}; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 6 | my $ctx = $class->new(%args); | |||||||||||
| 23 | Devel::Declare->setup_for( | ||||||||||||
| 24 | $args{into}, { | ||||||||||||
| 25 | 13 | ▶ | test => { const => sub { $ctx->parser(@_) } }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | } | ||||||||||||
| 27 | 6 | ); | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 13 | ▶ | sub parse_proto { | ||||||||||
|
Subroutine
parse_proto: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 31 | 13 | my ($self, $proto) = @_; | |||||||||||
| 32 | # todo: warn about bad syntax | ||||||||||||
| 33 | 13 | return [ grep { /[A-Za-z]+/} split /[^:_A-Za-z0-9+]+/, $proto ]; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 13 | ▶ | sub parser { | ||||||||||
|
Subroutine
parser: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 37 | 13 | my $self = shift; | |||||||||||
| 38 | 13 | $self->init(@_); | |||||||||||
| 39 | |||||||||||||
| 40 | 13 | $self->skip_declarator; | |||||||||||
| 41 | 13 | my $name = $self->strip_name; | |||||||||||
| 42 | 13 | ▶ | my $raw_proto = $self->strip_proto || ''; | ||||||||||
|
Condition100%2/2
$self->strip_proto || ''
MC/DC100%1/1
$self->strip_proto || ''
$self->strip_proto
Truth table100%2/2
A
A= $self->strip_proto
| |||||||||||||
| 43 | 13 | ▶ | my $attrs = $self->strip_attrs || ''; | ||||||||||
|
Condition50%1/2
$self->strip_attrs || ''
MC/DC0%0/1
$self->strip_attrs || ''
$self->strip_attrs
Truth table50%1/2
A
A= $self->strip_attrs
| |||||||||||||
| 44 | 13 | my $requested_traits = $self->parse_proto($raw_proto . ' '. $attrs); # why not let attrs be used too? | |||||||||||
| 45 | |||||||||||||
| 46 | 13 | my $inject = $self->scope_injector_call(); | |||||||||||
| 47 | 13 | $self->inject_if_block($inject. " my \$self = shift; my \$test = shift; "); | |||||||||||
| 48 | |||||||||||||
| 49 | 13 | my $pack = Devel::Declare::get_curstash_name; | |||||||||||
| 50 | 13 | ▶ | Devel::Declare::shadow_sub("${pack}::test", sub (&) { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 51 | 13 | my $test_method = shift; | |||||||||||
| 52 | 13 | $pack->meta->add_test( $name, $test_method, $requested_traits ); | |||||||||||
| 53 | 13 | }); | |||||||||||
| 54 | |||||||||||||
| 55 | 13 | return; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 3 | 1; | |||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | =pod | ||||||||||||
| 63 | |||||||||||||
| 64 | =head1 NAME | ||||||||||||
| 65 | |||||||||||||
| 66 | Test::Sweet::Keyword::Test - provides the C<test> keyword | ||||||||||||
| 67 | |||||||||||||
| 68 | =head1 VERSION | ||||||||||||
| 69 | |||||||||||||
| 70 | version 0.03 | ||||||||||||
| 71 | |||||||||||||
| 72 | =head1 AUTHOR | ||||||||||||
| 73 | |||||||||||||
| 74 | Jonathan Rockway <jrockway@cpan.org> | ||||||||||||
| 75 | |||||||||||||
| 76 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 77 | |||||||||||||
| 78 | This software is copyright (c) 2011 by Jonathan Rockway. | ||||||||||||
| 79 | |||||||||||||
| 80 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 81 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 82 | |||||||||||||
| 83 | =cut | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | __END__ | ||||||||||||