This file is indexed.

/usr/share/perl5/Courriel/Role/HeaderWithAttributes.pm is in libcourriel-perl 0.45-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
package Courriel::Role::HeaderWithAttributes;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '0.45';

use Courriel::HeaderAttribute;
use Courriel::Helpers qw( parse_header_with_attributes );
use Courriel::Types qw( HashRef NonEmptyStr );
use Params::ValidationCompiler qw( validation_for );
use Scalar::Util qw( blessed reftype );

use MooseX::Role::Parameterized;

parameter main_value_key => (
    isa      => NonEmptyStr,
    required => 1,
);

parameter main_value_method => (
    isa => NonEmptyStr,
);

has _attributes => (
    traits   => ['Hash'],
    is       => 'ro',
    isa      => HashRef ['Courriel::HeaderAttribute'],
    init_arg => 'attributes',
    default  => sub { {} },
    handles  => {
        attributes      => 'elements',
        _attribute      => 'get',
        _set_attribute  => 'set',
        _has_attributes => 'count',
    },
);

around BUILDARGS => sub {
    my $orig  = shift;
    my $class = shift;

    my $p = $class->$orig(@_);

    return $p
        unless $p->{attributes} && reftype( $p->{attributes} ) eq 'HASH';

    for my $name ( keys %{ $p->{attributes} } ) {
        my $lc_name = lc $name;
        $p->{attributes}{$lc_name} = delete $p->{attributes}{$name};

        next if blessed( $p->{attributes}{$lc_name} );

        $p->{attributes}{$lc_name} = Courriel::HeaderAttribute->new(
            name  => $name,
            value => $p->{attributes}{$name},
        );
    }

    return $p;
};

sub attribute {
    my $self = shift;
    my $key  = shift;

    return unless defined $key;

    return $self->_attribute( lc $key );
}

{
    my $validator = validation_for(
        params => [ { type => NonEmptyStr } ],
    );

    sub attribute_value {
        my $self = shift;
        my ($name) = $validator->(@_);

        my $attr = $self->attribute($name);

        return $attr ? $attr->value : undef;
    }
}

sub _attributes_as_string {
    my $self = shift;

    my $attr = $self->_attributes;

    return join '; ', map { $attr->{$_}->as_string } sort keys %{$attr};
}

{
    my $validator = validation_for(
        params => [
            name  => { type => NonEmptyStr, optional => 1 },
            value => { type => NonEmptyStr },
        ],
        named_to_list => 1,
    );

    role {
        my $p = shift;

        my $main_value_key = $p->main_value_key;

        method new_from_value => sub {
            my $class = shift;
            my ( $name, $value ) = $validator->(@_);

            my ( $main_value, $attributes )
                = parse_header_with_attributes($value);

            my %p = (
                value           => $value,
                $main_value_key => $main_value,
                attributes      => $attributes,
            );

            $p{name} = $name if defined $name;

            return $class->new(%p);
        };

        my $main_value_meth = $p->main_value_method || $p->main_value_key;

        method as_header_value => sub {
            my $self = shift;

            my $string = $self->$main_value_meth;

            if ( $self->_has_attributes ) {
                $string .= '; ';
                $string .= $self->_attributes_as_string;
            }

            return $string;
        };
    }
}

1;