This file is indexed.

/usr/share/perl5/HTML/Widget/Container.pm is in libhtml-widget-perl 1.11-4.

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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package HTML::Widget::Container;

use warnings;
use strict;
use base 'Class::Accessor::Fast';

__PACKAGE__->mk_accessors(qw/element label error javascript passive name/);

use overload '""' => sub { return shift->as_xml }, fallback => 1;

*js        = \&javascript;
*js_xml    = \&javascript_xml;
*field     = \&element;
*field_xml = \&element_xml;

=head1 NAME

HTML::Widget::Container - Container

=head1 SYNOPSIS

    my $container  = $form->element('foo');
    
    my $field = $container->field;
    my $error = $container->error;
	my $label = $container->label;

    my $field_xml      = $container->field_xml; 
    my $error_xml      = $container->error_xml;
    my $javascript_xml = $container->javascript_xml;

    my $xml = $container->as_xml;
	# $xml eq "$container"

    my $javascript = $container->javascript;

=head1 DESCRIPTION

Container.

=head1 METHODS

=head2 as_xml

Return Value: $xml

=cut

sub as_xml {
    my $self = shift;
    my $xml  = '';
    $xml .= $self->element_xml    if $self->element;
    $xml .= $self->javascript_xml if $self->javascript;
    $xml .= $self->error_xml      if $self->error;
    return $xml;
}

=head2 _build_element

Arguments: $element

Return Value: @elements

Convert $element to L<HTML::Element> object. Accepts arrayref.

If you wish to change the rendering behaviour of HTML::Widget; specifically, 
the handling of elements which are array-refs, you can specify 
L<HTML::Widget::Element/container_class> to a custom class which just 
overrides this function.

=cut

sub _build_element {
    my ( $self, $element ) = @_;

    return () unless $element;

    if ( ref $element eq 'ARRAY' ) {
        return map { $self->_build_element($_) } @{$element};
    }

    return $self->build_single_element( $element->clone );
}

=head2 build_single_element

Arguments: $element

Return Value: $element

Convert $element to L<HTML::Element> object.

Called by L</_build_element>.

If you wish to change the rendering behaviour of HTML::Widget; specifically, 
the handling of an individual element, you can override this function.

=cut

sub build_single_element {
    my ( $self, $element ) = @_;

    my $class = $element->attr('class') || '';

    $element = $self->build_element_error($element);

    $element = $self->build_element_label( $element, $class );

    return $element;
}

=head2 build_element_error

Arguments: $element

Return Value: $element

Called by L</build_single_element>.

If you wish to change how an error is rendered, override this function.

=cut

sub build_element_error {
    my ( $self, $element ) = @_;

    if ( $self->error && $element->tag eq 'input' ) {
        $element = HTML::Element->new( 'span', class => 'fields_with_errors' )
            ->push_content($element);
    }

    return $element;
}

=head2 build_element_label

Arguments: $element, $class

Return Value: $element

Called by L</build_single_element>.

If you wish to change how an element's label is rendered, override this 
function.

The $class argument is the original class of the element, before 
L</build_element_error> was called.

=cut

sub build_element_label {
    my ( $self, $element, $class ) = @_;

    return $element unless defined $self->label;

    my $l = $self->label->clone;
    my $radiogroup;

    if ( $class eq 'radiogroup_fieldset' ) {
        $element->unshift_content($l);
        $radiogroup = 1;
    }
    elsif ( $self->error && $element->tag eq 'span' ) {

        # it might still be a radiogroup wrapped in an error span
        for my $elem ( $element->content_refs_list ) {
            next unless ref $$elem;
            if ( $$elem->attr('class') eq 'radiogroup_fieldset' ) {
                $$elem->unshift_content($l);
                $radiogroup = 1;
            }
        }
    }

    if ( !$radiogroup ) {

        # Do we prepend or append input to label?
        $element =
            ( $class eq 'checkbox' or $class eq 'radio' )
            ? $l->unshift_content($element)
            : $l->push_content($element);
    }

    return $element;
}

=head2 as_list

Return Value: @elements

Returns a list of L<HTML::Element> objects.

=cut

sub as_list {
    my $self = shift;
    my @list;
    push @list, $self->_build_element( $self->element );
    push @list, $self->javascript_element if $self->javascript;
    push @list, $self->error if $self->error;
    return @list;
}

=head2 element

=head2 field

Arguments: $element

L</field> is an alias for L</element>.

=head2 element_xml

=head2 field_xml

Return Value: $xml

L</field_xml> is an alias for L</element_xml>.

=cut

sub element_xml {
    my $self = shift;
    my @e    = $self->_build_element;
    return join( '',
        map( { $_->as_XML } $self->_build_element( $self->element ) ) )
        || '';
}

=head2 error

Arguments: $error

Return Value: $error

=head2 error_xml

Return Value: $xml

=cut

sub error_xml {
    my $self = shift;
    return $self->error ? $self->error->as_XML : '';
}

=head2 javascript

=head2 js

Arguments: $javascript

Return Value: $javascript

L</js> is an alias for L</javascript>.

=head2 javascript_element

Return Value: $javascript_element

Returns javascript in a script L<HTML::Element>.

=cut

sub javascript_element {
    my $self    = shift;
    my $script  = HTML::Element->new( 'script', type => 'text/javascript' );
    my $content = "\n<!--\n" . $self->javascript . "\n//-->\n";
    my $literal = HTML::Element->new( '~literal', text => $content );
    $script->push_content($literal);
    return $script;
}

=head2 javascript_xml

=head2 js_xml

Return Value: $javascript_xml

Returns javascript in a script block.

L</js_xml> is an alias for L</javascript_xml>.

=cut

sub javascript_xml {
    my $self = shift;
    return $self->javascript_element->as_HTML('<>&');
}

=head1 AUTHOR

Sebastian Riedel, C<sri@oook.de>

=head1 LICENSE

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

=cut

1;