Perl-Critic-Policy-logicLAB-RequireSheBang

 view release on metacpan or  search on metacpan

lib/Perl/Critic/Policy/logicLAB/RequireSheBang.pm  view on Meta::CPAN

            $ #end of string
        }{}xsm;
    }

    if ( $self->{debug} && $shebang && $cli ) {
        print {*STDERR} "$DEBUG: we got a shebang line:\n";
        print {*STDERR} '>' . $shebang . $cli . "<\n";

        print {*STDERR} "$DEBUG: comparing against formats:\n";
        print {*STDERR} Dumper $self->{_formats};
        print {*STDERR} "\n";

    }
    elsif ( $self->{debug} ) {
        print {*STDERR} "$DEBUG: not a shebang, ignoring...\n";
    }

    if ( $shebang && none { ( $shebang . $cli ) eq $_ } @{ $self->{_formats} } )
    {

        if ( $self->{debug} ) {
            print {*STDERR} "$DEBUG: we got a violation:\n";
            print {*STDERR} '>' . $shebang . $cli . "<\n";
        }

        return $self->violation(
            q{she-bang line not conforming with requirement},
            $EXPL, $element );
    }

    return;
}

sub initialize_if_enabled {
    my ( $self, $config ) = @_;

    #Formats:
    #Setting the default
    $self->{_formats} = [ ('#!/usr/local/bin/perl') ];

    #fetching configured formats
    my $formats = $config->get('formats');

    #parsing configured formats, see also _parse_formats
    if ($formats) {
        $self->{_formats} = $self->_parse_formats($formats);
    }

    #debug
    $self->{debug} = $config->get('debug') || 0;

    #exempt_modules
    $self->{exempt_modules} = $config->get('exempt_modules') || 1;

    return $TRUE;
}

sub _parse_formats {
    my ( $self, $config_string ) = @_;

    my @formats = split m{ \s* [||]+ \s* }xsm, $config_string;

    return \@formats;
}

1;

__END__

=pod

=begin markdown

[![CPAN version](https://badge.fury.io/pl/Perl-Critic-Policy-logicLAB-RequireSheBang.svg)](http://badge.fury.io/pl/Perl-Critic-Policy-logicLAB-RequireSheBang)
[![Build Status](https://travis-ci.org/jonasbn/pcplrsb.svg?branch=master)](https://travis-ci.org/jonasbn/pcplrsb)
[![Coverage Status](https://coveralls.io/repos/jonasbn/pcplrsb/badge.png)](https://coveralls.io/r/jonasbn/pcplrsb)

=end markdown

=head1 NAME

Perl::Critic::Policy::logicLAB::RequireSheBang - simple policy for keeping your shebang line uniform

=head1 AFFILIATION

This policy is a policy in the Perl::Critic::logicLAB distribution. The policy
is themed: logiclab.

=head1 VERSION

This documentation describes version 0.07.

=head1 DESCRIPTION

This policy is intended in guarding your use of the shebang line. It assists
in making sure that your shebang line adheres to certain formats.

The default format is

    #!/usr/local/bin/perl

You can however specify another or define your own in the configuration of the
policy.

B<NB> this policy does currently not warn about missing shebang lines, it only
checks shebang lines encountered.

=head1 CONFIGURATION AND ENVIRONMENT

This policy allow you to configure the contents of the shebang lines you
want to allow using L</formats>.

=head2 formats

    [logicLAB::RequireSheBang]
    formats = #!/usr/local/bin/perl || #!/usr/bin/perl || #!perl || #!env perl

Since the default shebang line enforced by the policy is:

    #!/usr/local/bin/perl



( run in 3.178 seconds using v1.01-cache-2.11-cpan-71847e10f99 )