Mardem-RefactoringPerlCriticPolicies

 view release on metacpan or  search on metacpan

lib/Mardem/RefactoringPerlCriticPolicies/Util.pm  view on Meta::CPAN

our @EXPORT_OK = qw( search_for_block_keyword );

Readonly::Array my @BLOCK_SEARCH_KEYWORD => qw(
    SUB
    IF ELSIF UNLESS
    WHILE UNTIL
    DO
    FOR FOREACH
    EVAL
    SORT MAP GREP
    BEGIN UNITCHECK CHECK INIT END
    PACKAGE );

Readonly::Scalar my $MAX_KEYWORD_LOOKUP_DEPTH => 10;

sub _keyword_in_searchlist
{
    my ( $keyword ) = @_;

    $keyword = uc $keyword;

t/40-complex-block.t  view on Meta::CPAN

    my $desc = _get_description_from_violations( @violations );

    like $desc, qr/"BEGIN"\scode-block\s.*\scomplexity\sscore\s[(]\d+[)]/aaixmso,
        'violation description correct with BEGIN';
}

#####

{
    my $code = <<'END_OF_STRING';
        UNITCHECK {
            print 'test ' . ( 1 == 0 && 2 == 3 || 4 == 6 ? '' : 'not ') . 'reached'."\n";
        };
END_OF_STRING

    my @violations = _check_perl_critic( \$code, $MCC_VALUE_1 );

    ok !!@violations, 'complex tinaray within UNITCHECK block';

    my $desc = _get_description_from_violations( @violations );

    like $desc, qr/"UNITCHECK"\scode-block\s.*\scomplexity\sscore\s[(]\d+[)]/aaixmso,
        'violation description correct with UNITCHECK';
}

#####

{
    my $code = <<'END_OF_STRING';
        CHECK {
            print 'test ' . ( 1 == 0 && 2 == 3 || 4 == 6 ? '' : 'not ') . 'reached'."\n";
        };
END_OF_STRING

t/60-large-block.t  view on Meta::CPAN

    my $desc = _get_description_from_violations( @violations );

    like $desc, qr/"BEGIN"\scode-block\s.*\sstatement\scount\s[(]\d+[)]/aaixmso,
        'violation description correct with BEGIN';
}

#####

{
    my $code = <<'END_OF_STRING';
        UNITCHECK {
            print __LINE__;
            return;
        };
END_OF_STRING

    my @violations = _check_perl_critic( \$code, $STATEMENT_COUNT_LIMIT_VALUE_1 );

    ok !!@violations, 'UNITCHECK with two statements';

    my $desc = _get_description_from_violations( @violations );

    like $desc, qr/"UNITCHECK"\scode-block\s.*\sstatement\scount\s[(]\d+[)]/aaixmso,
        'violation description correct with UNITCHECK';
}

#####

{
    my $code = <<'END_OF_STRING';
        CHECK {
            print __LINE__;
            return;
        };



( run in 2.318 seconds using v1.01-cache-2.11-cpan-748bfb374f4 )