Perl-Tidy

 view release on metacpan or  search on metacpan

lib/Perl/Tidy/Formatter.pm  view on Meta::CPAN

    # but it contains 'grep' and can be re-initialized in
    # sub initialize_grep_and_friends in a testing mode.
    %block_type_map = (
        'unless'  => 'if',
        'else'    => 'if',
        'elsif'   => 'if',
        'when'    => 'if',
        'default' => 'if',
        'case'    => 'if',
        'sort'    => 'map',
        'grep'    => 'map',
    );

    @q = qw( if unless );
    $is_if_unless{$_} = 1 for @q;

    @q = qw( if elsif );
    $is_if_elsif{$_} = 1 for @q;

    @q = qw( if unless elsif );
    $is_if_unless_elsif{$_} = 1 for @q;

    @q = qw( if unless elsif else );
    $is_if_unless_elsif_else{$_} = 1 for @q;

    @q = qw( elsif else );
    $is_elsif_else{$_} = 1 for @q;

    @q = qw( and or err );
    $is_and_or{$_} = 1 for @q;

    # Identify certain operators which often occur in chains.
    # Note: the minus (-) causes a side effect of padding of the first line in
    # something like this (by sub set_logical_padding):
    #    Checkbutton => 'Transmission checked',
    #   -variable    => \$TRANS
    # This usually improves appearance so it seems ok.
    @q = qw( && || and or : ? . + - * / );
    $is_chain_operator{$_} = 1 for @q;

    # Operators that the user can request break before or after.
    # Note that some are keywords
    @all_operators = qw{
      % + - * / x != == >= <= =~ !~ < > | &
      = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
      . : ? && || and or err xor
    };

    my @binary_ops = qw#
      !~ =~ . .. : && || // = + - x
      **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //=
      <= >= == != > < % * / ? & | ** <=> ~~ !~~ <<~
      >> << ^
      ^. |. &. ^.= |.= &.= ^^
      #;
    $is_binary_operator_type{$_} = 1 for @binary_ops;

    # We can remove semicolons after blocks preceded by these keywords
    @q = qw(
      BEGIN     END      CHECK INIT    AUTOLOAD DESTROY
      UNITCHECK continue if    elsif   else     unless
      while     until    for   foreach given    when
      default
    );
    $is_block_without_semicolon{$_} = 1 for @q;

    # We will allow semicolons to be added within these block types
    # as well as sub and package blocks.
    # NOTES:
    # 1. Note that these keywords are omitted:
    #     switch case given when default sort map grep
    # 2. It is also ok to add for sub and package blocks and a labeled block
    # 3. But not okay for other perltidy types including:
    #     { } ; G t
    # 4. Test files: blktype.t, blktype1.t, semicolon.t
    @q = qw( BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif
      else unless do while until eval for foreach );
    $ok_to_add_semicolon_for_block_type{$_} = 1 for @q;

    # 'L' is token for opening { at hash key
    @q = qw< L { ( [ >;
    $is_opening_type{$_} = 1 for @q;

    # 'R' is token for closing } at hash key
    @q = qw< R } ) ] >;
    $is_closing_type{$_} = 1 for @q;

    @q = qw< { ( [ >;
    $is_opening_token{$_} = 1 for @q;

    @q = qw< } ) ] >;
    $is_closing_token{$_} = 1 for @q;

    @q = qw( ? : );
    $is_ternary{$_} = 1 for @q;

    @q = qw< { ( [ ? >;
    $is_opening_sequence_token{$_} = 1 for @q;

    @q = qw< } ) ] : >;
    $is_closing_sequence_token{$_} = 1 for @q;

    %matching_token = (
        '{' => '}',
        '(' => ')',
        '[' => ']',
        '?' => ':',

        '}' => '{',
        ')' => '(',
        ']' => '[',
        ':' => '?',
    );

    # a hash needed by sub break_lists for labeling containers
    @q = qw( k => && || ? : . );
    $is_container_label_type{$_} = 1 for @q;

    @q = qw( die confess croak warn );
    $is_die_confess_croak_warn{$_} = 1 for @q;

    @q = qw( my our local );
    $is_my_our_local{$_} = 1 for @q;

    # Braces -bbht etc must follow these. Note: experimentation with
    # including a simple comma shows that it adds little and can lead
    # to poor formatting in complex lists.
    @q = qw( = => );
    $is_equal_or_fat_comma{$_} = 1 for @q;

    # Removed 'h' (no longer needed after updated b1523)
    @q = qw( => ; f );
    push @q, ',';
    $is_counted_type{$_} = 1 for @q;

    # Tokens where --keep-old-break-xxx flags make soft breaks instead



( run in 0.454 second using v1.01-cache-2.11-cpan-5735350b133 )