This file is indexed.

/usr/share/perl5/Layout/Manager/Flow.pm is in liblayout-manager-perl 0.34-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package Layout::Manager::Flow;
use Moose;

extends 'Layout::Manager';

use Moose::Util::TypeConstraints;

enum 'Layout::Manager::Flow::Anchors' => qw(north south east west);

has 'anchor' => (
    is => 'rw',
    isa => 'Layout::Manager::Flow::Anchors',
    default => sub { 'north' }
);

has 'expand' => (
    is => 'rw',
    isa => 'Bool',
    default => sub { 1 }
);

has 'used' => (
    is => 'rw',
    isa => 'ArrayRef',
    default => sub { [0, 0] }
);

has 'wrap' => (
    is => 'rw',
    isa => 'Bool',
    default => sub { 0 }
);

override('do_layout', sub {
    my ($self, $container) = @_;

    my $bbox = $container->inside_bounding_box;

    my $cwidth = $bbox->width;
    my $cheight = $bbox->height;

    my $ox = $bbox->origin->x;
    my $oy = $bbox->origin->y;

    my $anch = $self->anchor;

    my @lines;
    my $yused = $oy;
    my $xused = $ox;

    my $line = 0;
    foreach my $comp (@{ $container->components }) {

        next unless defined($comp) && $comp->visible;

        $comp->width($comp->minimum_width);
        $comp->height($comp->minimum_height);

        # If we aren't wrapping, expand to fill the whole space
        if(($anch eq 'north') || ($anch eq 'south')) {
            unless($self->wrap) {
                $comp->width($cwidth) if $cwidth;
            }
        } else {
            unless($self->wrap) {
                $comp->height($cheight) if $cheight;
            }
        }

        my $comp_height = $comp->height;
        my $comp_width = $comp->width;

        unless(defined($lines[$line])) {
            $lines[$line] = {
                tallest => $comp_height || 0,
                widest => $comp_width || 0,
                height => 0,
                width => 0,
                components => []
            };
        }

        # Keep up with the tallest component we find
        if(!($lines[$line]->{tallest}) || $comp_height > $lines[$line]->{tallest}) {
            $lines[$line]->{tallest} = $comp_height;
        }
        # Keep up with the widest component we find
        if(!($lines[$line]->{widest}) || $comp_width > $lines[$line]->{widest}) {
            $lines[$line]->{widest} = $comp_width;
        }

        my $co = $comp->origin;

        if($anch eq 'north') {

            # No wrapping
            $co->x($ox);
            $co->y($oy + $lines[$line]->{height});
            $lines[$line]->{height} += $comp_height;
            unless($lines[$line]->{width}) {
                $lines[$line]->{width} = $comp_width;
            }
        } elsif($anch eq 'south') {

            # No wrapping
            $co->x($ox);
            $co->y($oy + $cheight - $comp_height - $lines[$line]->{height});
            $lines[$line]->{height} += $comp_height;
            unless($lines[$line]->{width}) {
                $lines[$line]->{width} = $comp_width;
            }
        } elsif($anch eq 'east') {

            if(
                # It doesn't matter if we are supposed to wrap if we have
                # no width, we'll make this thing as big as it needs to be
                ($cwidth > 0) &&
                # if we are wrapping
                ($self->wrap) &&
                # and the current component would overflow...
                ($lines[$line]->{width} + $comp_width > $cwidth) &&
                scalar(@{ $lines[$line]->{components} })
            ) {
                # We've been asked to wrap and this component is too wide
                # to fit.  Move down by the height of the tallest component
                # then reset the tallest variable.
                $yused += $lines[$line]->{tallest};
                $co->x($cwidth - $comp_width - $ox);
                $co->y($oy + $yused);

                $line++;

                $lines[$line]->{width} = $ox + $comp_width;
                $lines[$line]->{tallest} = $comp_height;
            } else {
                $co->x($ox + $cwidth - $comp_width - $lines[$line]->{width});
                $co->y($yused);
                $lines[$line]->{width} += $comp_width;
            }
        } else {

            # WEST
            if(
                # It doesn't matter if we are supposed to wrap if we have
                # no width, we'll make this thing as big as it needs to be
                ($cwidth > 0) &&
                # if we are wrapping
                ($self->wrap) &&
                # and the current component would overflow...
                ($lines[$line]->{width} + $comp_width > $cwidth) &&
                scalar(@{ $lines[$line]->{components} })
            ) {
                # We've been asked to wrap and this component is too wide
                # to fit.  Move down by the height of the tallest component
                # then reset the tallest variable.
                $yused += $lines[$line]->{tallest};
                $co->x($ox);
                $co->y($yused);

                $line++;
                $lines[$line]->{width} = $ox + $comp_width;
                $lines[$line]->{tallest} = $comp_height;
            } else {
                $co->x($ox + $lines[$line]->{width});
                $co->y($yused);
                $lines[$line]->{width} += $comp_width;
            }
        }
        push(@{ $lines[$line]->{components} }, $comp);
    }


    my $fwidth = 0;
    my $fheight = 0;

    foreach my $l (@lines) {
        unless($l->{height}) {
            $l->{height} = $l->{tallest};
        }
        $fheight += $l->{height};
        if($l->{width} > $fwidth) {
            $fwidth += $l->{width};
        }
    }
    $self->used([$fwidth, $fheight]);

    $container->minimum_width($fwidth + $container->outside_width);
    $container->minimum_height($fheight + $container->outside_height);

    # Size our container, now that everything is done.
    if($container->width < $container->minimum_width) {
        $container->width($container->minimum_width);
    }
    if($container->height < $container->minimum_height) {
        $container->height($container->minimum_height);
    }

    super;

    return 1;
});

__PACKAGE__->meta->make_immutable;

no Moose;

1;
__END__
=head1 NAME

Layout::Manager::Flow - Directional layout manager

=head1 DESCRIPTION

Layout::Manager::Flow is a layout manager that anchors components in one of
the four cardinal directions.

When you instantiate a Flow manager, you may supply it with an anchor value
which may be one of north, south, east or west.  The example below shows
how the default anchor value of north works when you add two components.

                 north
  +--------------------------------+
  |           component 1          |
  +--------------------------------+
  |           component 2          |
  +--------------------------------+
  |                                |
  |                                |
  |                                |
  +--------------------------------+

Components are placed in the order they are added.  If two items are added
with a 'north' anchor then the first item will be rendered above the
second.  Components will be expanded to take up all space perpendicular to
their anchor.  North and south will expand widths while east and west will
expand heights.

Flow is similar to Java's
L<FlowLayout|http://java.sun.com/docs/books/tutorial/uiswing/layout/flow.html>.
It does not, however, center components.  This features may be added in the
future if they are needed.

=head1 SYNOPSIS

  $cont->add_component($comp1);
  $cont->add_component($comp2);

  my $lm = Layout::Manager::Flow->new(anchor => 'north');
  $lm->do_layout($cont);

=head1 ATTRIBUTES

=head2 anchor

The direction this manager is anchored.  Valid values are north, south, east
and west.

=head2 used

Returns the amount of space used an arrayref in the form of C<[ $width, $height ]>.

=head2 wrap

If set to a true value, then component will be 'wrapped' when they do not
fit.  B<This currently only works for East and West anchored layouts.>

=head1 METHODS

=head2 do_layout

Size and position the components in this layout.

=head1 AUTHOR

Cory Watson, C<< <gphat@cpan.org> >>

=head1 COPYRIGHT & LICENSE

Copyright 2008 by Cory G Watson

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.