"Fossies" - the Fresh Open Source Software Archive

Member "Perl-Tidy-20200110/lib/Perl/Tidy/VerticalAligner/Line.pm" (7 Jan 2020, 6774 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 "Line.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::VerticalAligner::Line class supplies an object to
    4 # contain a single output line
    5 #
    6 #####################################################################
    7 
    8 package Perl::Tidy::VerticalAligner::Line;
    9 use strict;
   10 use warnings;
   11 our $VERSION = '20200110';
   12 
   13 {
   14 
   15     ##use Carp;
   16 
   17     my %default_data = (
   18         jmax                      => undef,
   19         jmax_original_line        => undef,
   20         rtokens                   => undef,
   21         rfields                   => undef,
   22         rpatterns                 => undef,
   23         indentation               => undef,
   24         leading_space_count       => undef,
   25         outdent_long_lines        => undef,
   26         list_type                 => undef,
   27         is_hanging_side_comment   => undef,
   28         ralignments               => [],
   29         maximum_line_length       => undef,
   30         rvertical_tightness_flags => undef,
   31         is_terminal_ternary       => undef,
   32         is_terminal_else          => undef,
   33         j_terminal_match          => undef,
   34     );
   35     {
   36 
   37         # methods to count object population
   38         my $_count = 0;
   39         sub get_count        { return $_count; }
   40         sub _increment_count { return ++$_count }
   41         sub _decrement_count { return --$_count }
   42     }
   43 
   44     # Constructor may be called as a class method
   45     sub new {
   46         my ( $caller, %arg ) = @_;
   47         my $caller_is_obj = ref($caller);
   48         my $class         = $caller_is_obj || $caller;
   49         ##no strict "refs";
   50         my $self = bless {}, $class;
   51 
   52         $self->{_ralignments} = [];
   53 
   54         foreach my $key ( keys %default_data ) {
   55             my $_key = '_' . $key;
   56 
   57             # Caller keys do not have an underscore
   58             if    ( exists $arg{$key} ) { $self->{$_key} = $arg{$key} }
   59             elsif ($caller_is_obj)      { $self->{$_key} = $caller->{$_key} }
   60             else { $self->{$_key} = $default_data{$_key} }
   61         }
   62 
   63         $self->_increment_count();
   64         return $self;
   65     }
   66 
   67     sub DESTROY {
   68         my $self = shift;
   69         $self->_decrement_count();
   70         return;
   71     }
   72 
   73     sub get_jmax { my $self = shift; return $self->{_jmax} }
   74 
   75     sub get_jmax_original_line {
   76         my $self = shift;
   77         return $self->{_jmax_original_line};
   78     }
   79     sub get_rtokens     { my $self = shift; return $self->{_rtokens} }
   80     sub get_rfields     { my $self = shift; return $self->{_rfields} }
   81     sub get_rpatterns   { my $self = shift; return $self->{_rpatterns} }
   82     sub get_indentation { my $self = shift; return $self->{_indentation} }
   83 
   84     sub get_j_terminal_match {
   85         my $self = shift;
   86         return $self->{_j_terminal_match};
   87     }
   88 
   89     sub get_is_terminal_else {
   90         my $self = shift;
   91         return $self->{_is_terminal_else};
   92     }
   93 
   94     sub get_is_terminal_ternary {
   95         my $self = shift;
   96         return $self->{_is_terminal_ternary};
   97     }
   98 
   99     sub get_leading_space_count {
  100         my $self = shift;
  101         return $self->{_leading_space_count};
  102     }
  103 
  104     sub get_outdent_long_lines {
  105         my $self = shift;
  106         return $self->{_outdent_long_lines};
  107     }
  108     sub get_list_type { my $self = shift; return $self->{_list_type} }
  109 
  110     sub get_is_hanging_side_comment {
  111         my $self = shift;
  112         return $self->{_is_hanging_side_comment};
  113     }
  114 
  115     sub get_rvertical_tightness_flags {
  116         my $self = shift;
  117         return $self->{_rvertical_tightness_flags};
  118     }
  119 
  120     sub set_column {
  121         ## FIXME: does caller ever supply $val??
  122         my ( $self, $j, $val ) = @_;
  123         return $self->{_ralignments}->[$j]->set_column($val);
  124     }
  125 
  126     sub get_alignment {
  127         my ( $self, $j ) = @_;
  128         return $self->{_ralignments}->[$j];
  129     }
  130     sub get_alignments { my $self = shift; return @{ $self->{_ralignments} } }
  131 
  132     sub get_column {
  133         my ( $self, $j ) = @_;
  134         return $self->{_ralignments}->[$j]->get_column();
  135     }
  136 
  137     sub get_starting_column {
  138         my ( $self, $j ) = @_;
  139         return $self->{_ralignments}->[$j]->get_starting_column();
  140     }
  141 
  142     sub increment_column {
  143         my ( $self, $k, $pad ) = @_;
  144         $self->{_ralignments}->[$k]->increment_column($pad);
  145         return;
  146     }
  147 
  148     sub set_alignments {
  149         my ( $self, @args ) = @_;
  150         @{ $self->{_ralignments} } = @args;
  151         return;
  152     }
  153 
  154     sub current_field_width {
  155         my ( $self, $j ) = @_;
  156         if ( $j == 0 ) {
  157             return $self->get_column($j);
  158         }
  159         else {
  160             return $self->get_column($j) - $self->get_column( $j - 1 );
  161         }
  162     }
  163 
  164     sub field_width_growth {
  165         my ( $self, $j ) = @_;
  166         return $self->get_column($j) - $self->get_starting_column($j);
  167     }
  168 
  169     sub starting_field_width {
  170         my ( $self, $j ) = @_;
  171         if ( $j == 0 ) {
  172             return $self->get_starting_column($j);
  173         }
  174         else {
  175             return $self->get_starting_column($j) -
  176               $self->get_starting_column( $j - 1 );
  177         }
  178     }
  179 
  180     sub increase_field_width {
  181 
  182         my ( $self, $j, $pad ) = @_;
  183         my $jmax = $self->get_jmax();
  184         for my $k ( $j .. $jmax ) {
  185             $self->increment_column( $k, $pad );
  186         }
  187         return;
  188     }
  189 
  190     sub get_available_space_on_right {
  191         my $self = shift;
  192         my $jmax = $self->get_jmax();
  193         return $self->{_maximum_line_length} - $self->get_column($jmax);
  194     }
  195 
  196     sub set_jmax { my ( $self, $val ) = @_; $self->{_jmax} = $val; return }
  197 
  198     sub set_jmax_original_line {
  199         my ( $self, $val ) = @_;
  200         $self->{_jmax_original_line} = $val;
  201         return;
  202     }
  203 
  204     sub set_rtokens {
  205         my ( $self, $val ) = @_;
  206         $self->{_rtokens} = $val;
  207         return;
  208     }
  209 
  210     sub set_rfields {
  211         my ( $self, $val ) = @_;
  212         $self->{_rfields} = $val;
  213         return;
  214     }
  215 
  216     sub set_rpatterns {
  217         my ( $self, $val ) = @_;
  218         $self->{_rpatterns} = $val;
  219         return;
  220     }
  221 
  222     sub set_indentation {
  223         my ( $self, $val ) = @_;
  224         $self->{_indentation} = $val;
  225         return;
  226     }
  227 
  228     sub set_leading_space_count {
  229         my ( $self, $val ) = @_;
  230         $self->{_leading_space_count} = $val;
  231         return;
  232     }
  233 
  234     sub set_outdent_long_lines {
  235         my ( $self, $val ) = @_;
  236         $self->{_outdent_long_lines} = $val;
  237         return;
  238     }
  239 
  240     sub set_list_type {
  241         my ( $self, $val ) = @_;
  242         $self->{_list_type} = $val;
  243         return;
  244     }
  245 
  246     sub set_is_hanging_side_comment {
  247         my ( $self, $val ) = @_;
  248         $self->{_is_hanging_side_comment} = $val;
  249         return;
  250     }
  251 
  252     sub set_alignment {
  253         my ( $self, $j, $val ) = @_;
  254         $self->{_ralignments}->[$j] = $val;
  255         return;
  256     }
  257 
  258 }
  259 
  260 1;
  261