"Fossies" - the Fresh Open Source Software Archive

Member "Perl-Tidy-20200110/lib/Perl/Tidy/IndentationItem.pm" (7 Jan 2020, 6722 Bytes) of package /linux/misc/Perl-Tidy-20200110.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "IndentationItem.pm" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 20191203_vs_20200110.

    1 #####################################################################
    2 #
    3 # the Perl::Tidy::IndentationItem class supplies items which contain
    4 # how much whitespace should be used at the start of a line
    5 #
    6 #####################################################################
    7 
    8 package Perl::Tidy::IndentationItem;
    9 use strict;
   10 use warnings;
   11 our $VERSION = '20200110';
   12 
   13 sub new {
   14 
   15     # Create an 'indentation_item' which describes one level of leading
   16     # whitespace when the '-lp' indentation is used.
   17     my (
   18         $class,               $spaces,           $level,
   19         $ci_level,            $available_spaces, $index,
   20         $gnu_sequence_number, $align_paren,      $stack_depth,
   21         $starting_index,
   22     ) = @_;
   23 
   24     my $closed            = -1;
   25     my $arrow_count       = 0;
   26     my $comma_count       = 0;
   27     my $have_child        = 0;
   28     my $want_right_spaces = 0;
   29     my $marked            = 0;
   30 
   31     # DEFINITIONS:
   32     # spaces             =>  # total leading white spaces
   33     # level              =>  # the indentation 'level'
   34     # ci_level           =>  # the 'continuation level'
   35     # available_spaces   =>  # how many left spaces available
   36     #                        # for this level
   37     # closed             =>  # index where we saw closing '}'
   38     # comma_count        =>  # how many commas at this level?
   39     # sequence_number    =>  # output batch number
   40     # index              =>  # index in output batch list
   41     # have_child         =>  # any dependents?
   42     # recoverable_spaces =>  # how many spaces to the right
   43     #                        # we would like to move to get
   44     #                        # alignment (negative if left)
   45     # align_paren        =>  # do we want to try to align
   46     #                        # with an opening structure?
   47     # marked             =>  # if visited by corrector logic
   48     # stack_depth        =>  # indentation nesting depth
   49     # starting_index     =>  # first token index of this level
   50     # arrow_count        =>  # how many =>'s
   51 
   52     return bless {
   53         _spaces             => $spaces,
   54         _level              => $level,
   55         _ci_level           => $ci_level,
   56         _available_spaces   => $available_spaces,
   57         _closed             => $closed,
   58         _comma_count        => $comma_count,
   59         _sequence_number    => $gnu_sequence_number,
   60         _index              => $index,
   61         _have_child         => $have_child,
   62         _recoverable_spaces => $want_right_spaces,
   63         _align_paren        => $align_paren,
   64         _marked             => $marked,
   65         _stack_depth        => $stack_depth,
   66         _starting_index     => $starting_index,
   67         _arrow_count        => $arrow_count,
   68     }, $class;
   69 }
   70 
   71 sub permanently_decrease_available_spaces {
   72 
   73     # make a permanent reduction in the available indentation spaces
   74     # at one indentation item.  NOTE: if there are child nodes, their
   75     # total SPACES must be reduced by the caller.
   76 
   77     my ( $item, $spaces_needed ) = @_;
   78     my $available_spaces = $item->get_available_spaces();
   79     my $deleted_spaces =
   80       ( $available_spaces > $spaces_needed )
   81       ? $spaces_needed
   82       : $available_spaces;
   83     $item->decrease_available_spaces($deleted_spaces);
   84     $item->decrease_SPACES($deleted_spaces);
   85     $item->set_recoverable_spaces(0);
   86 
   87     return $deleted_spaces;
   88 }
   89 
   90 sub tentatively_decrease_available_spaces {
   91 
   92     # We are asked to tentatively delete $spaces_needed of indentation
   93     # for an indentation item.  We may want to undo this later.  NOTE: if
   94     # there are child nodes, their total SPACES must be reduced by the
   95     # caller.
   96     my ( $item, $spaces_needed ) = @_;
   97     my $available_spaces = $item->get_available_spaces();
   98     my $deleted_spaces =
   99       ( $available_spaces > $spaces_needed )
  100       ? $spaces_needed
  101       : $available_spaces;
  102     $item->decrease_available_spaces($deleted_spaces);
  103     $item->decrease_SPACES($deleted_spaces);
  104     $item->increase_recoverable_spaces($deleted_spaces);
  105     return $deleted_spaces;
  106 }
  107 
  108 sub get_stack_depth {
  109     my $self = shift;
  110     return $self->{_stack_depth};
  111 }
  112 
  113 sub get_spaces {
  114     my $self = shift;
  115     return $self->{_spaces};
  116 }
  117 
  118 sub get_marked {
  119     my $self = shift;
  120     return $self->{_marked};
  121 }
  122 
  123 sub set_marked {
  124     my ( $self, $value ) = @_;
  125     if ( defined($value) ) {
  126         $self->{_marked} = $value;
  127     }
  128     return $self->{_marked};
  129 }
  130 
  131 sub get_available_spaces {
  132     my $self = shift;
  133     return $self->{_available_spaces};
  134 }
  135 
  136 sub decrease_SPACES {
  137     my ( $self, $value ) = @_;
  138     if ( defined($value) ) {
  139         $self->{_spaces} -= $value;
  140     }
  141     return $self->{_spaces};
  142 }
  143 
  144 sub decrease_available_spaces {
  145     my ( $self, $value ) = @_;
  146     if ( defined($value) ) {
  147         $self->{_available_spaces} -= $value;
  148     }
  149     return $self->{_available_spaces};
  150 }
  151 
  152 sub get_align_paren {
  153     my $self = shift;
  154     return $self->{_align_paren};
  155 }
  156 
  157 sub get_recoverable_spaces {
  158     my $self = shift;
  159     return $self->{_recoverable_spaces};
  160 }
  161 
  162 sub set_recoverable_spaces {
  163     my ( $self, $value ) = @_;
  164     if ( defined($value) ) {
  165         $self->{_recoverable_spaces} = $value;
  166     }
  167     return $self->{_recoverable_spaces};
  168 }
  169 
  170 sub increase_recoverable_spaces {
  171     my ( $self, $value ) = @_;
  172     if ( defined($value) ) {
  173         $self->{_recoverable_spaces} += $value;
  174     }
  175     return $self->{_recoverable_spaces};
  176 }
  177 
  178 sub get_ci_level {
  179     my $self = shift;
  180     return $self->{_ci_level};
  181 }
  182 
  183 sub get_level {
  184     my $self = shift;
  185     return $self->{_level};
  186 }
  187 
  188 sub get_sequence_number {
  189     my $self = shift;
  190     return $self->{_sequence_number};
  191 }
  192 
  193 sub get_index {
  194     my $self = shift;
  195     return $self->{_index};
  196 }
  197 
  198 sub get_starting_index {
  199     my $self = shift;
  200     return $self->{_starting_index};
  201 }
  202 
  203 sub set_have_child {
  204     my ( $self, $value ) = @_;
  205     if ( defined($value) ) {
  206         $self->{_have_child} = $value;
  207     }
  208     return $self->{_have_child};
  209 }
  210 
  211 sub get_have_child {
  212     my $self = shift;
  213     return $self->{_have_child};
  214 }
  215 
  216 sub set_arrow_count {
  217     my ( $self, $value ) = @_;
  218     if ( defined($value) ) {
  219         $self->{_arrow_count} = $value;
  220     }
  221     return $self->{_arrow_count};
  222 }
  223 
  224 sub get_arrow_count {
  225     my $self = shift;
  226     return $self->{_arrow_count};
  227 }
  228 
  229 sub set_comma_count {
  230     my ( $self, $value ) = @_;
  231     if ( defined($value) ) {
  232         $self->{_comma_count} = $value;
  233     }
  234     return $self->{_comma_count};
  235 }
  236 
  237 sub get_comma_count {
  238     my $self = shift;
  239     return $self->{_comma_count};
  240 }
  241 
  242 sub set_closed {
  243     my ( $self, $value ) = @_;
  244     if ( defined($value) ) {
  245         $self->{_closed} = $value;
  246     }
  247     return $self->{_closed};
  248 }
  249 
  250 sub get_closed {
  251     my $self = shift;
  252     return $self->{_closed};
  253 }
  254 1;