| 1 | package Locale::File::PO::Header::ContentTypeItem; ## no critic (TidyCode) | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 5 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 5 | ▶ | use MooseX::StrictConstructor; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 5 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 5 | our $VERSION = '0.004'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 5 | extends qw(Locale::File::PO::Header::Base); | |||||||||||||
| 10 | |||||||||||||||
| 11 | 5 | has name => ( | |||||||||||||
| 12 | is => 'rw', | ||||||||||||||
| 13 | isa => 'Str', | ||||||||||||||
| 14 | ); | ||||||||||||||
| 15 | |||||||||||||||
| 16 | has default => ( | ||||||||||||||
| 17 | is => 'rw', | ||||||||||||||
| 18 | isa => 'HashRef', | ||||||||||||||
| 19 | 3 | ▶ | trigger => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 3 | my ($self, $arg_ref) = @_; | |||||||||||||
| 21 | |||||||||||||||
| 22 | 3 | $self->default_content_type( $arg_ref->{'Content-Type'} ); | |||||||||||||
| 23 | 3 | $self->default_charset( $arg_ref->{charset} ); | |||||||||||||
| 24 | |||||||||||||||
| 25 | 3 | return $arg_ref; | |||||||||||||
| 26 | }, | ||||||||||||||
| 27 | 5 | ); | |||||||||||||
| 28 | |||||||||||||||
| 29 | 5 | has default_content_type => ( | |||||||||||||
| 30 | is => 'rw', | ||||||||||||||
| 31 | isa => 'Str', | ||||||||||||||
| 32 | ); | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 5 | has default_charset => ( | |||||||||||||
| 35 | is => 'rw', | ||||||||||||||
| 36 | isa => 'Str', | ||||||||||||||
| 37 | ); | ||||||||||||||
| 38 | |||||||||||||||
| 39 | has content_type => ( | ||||||||||||||
| 40 | is => 'rw', | ||||||||||||||
| 41 | isa => 'Str|Undef', | ||||||||||||||
| 42 | lazy => 1, | ||||||||||||||
| 43 | 1 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | return $self->default_content_type; | |||||||||||||
| 47 | }, | ||||||||||||||
| 48 | 5 | ▶ | trigger => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 49 | 5 | my ($self, $content_type, $current_content_type) = @_; | |||||||||||||
| 50 | |||||||||||||||
| 51 | 5 | return $self->trigger_helper({ | |||||||||||||
| 52 | new => $content_type, | ||||||||||||||
| 53 | current => $current_content_type, | ||||||||||||||
| 54 | default => scalar $self->default_content_type, | ||||||||||||||
| 55 | writer => 'content_type', | ||||||||||||||
| 56 | }); | ||||||||||||||
| 57 | }, | ||||||||||||||
| 58 | 5 | ); | |||||||||||||
| 59 | |||||||||||||||
| 60 | has charset => ( | ||||||||||||||
| 61 | is => 'rw', | ||||||||||||||
| 62 | isa => 'Str|Undef', | ||||||||||||||
| 63 | lazy => 1, | ||||||||||||||
| 64 | 1 | ▶ | default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 65 | 1 | my $self = shift; | |||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | return $self->default_charset; | |||||||||||||
| 68 | }, | ||||||||||||||
| 69 | 6 | ▶ | trigger => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 70 | 6 | my ($self, $charset, $current_charset) = @_; | |||||||||||||
| 71 | |||||||||||||||
| 72 | 6 | return $self->trigger_helper({ | |||||||||||||
| 73 | new => $charset, | ||||||||||||||
| 74 | current => $current_charset, | ||||||||||||||
| 75 | default => scalar $self->default_charset, | ||||||||||||||
| 76 | writer => 'charset', | ||||||||||||||
| 77 | }); | ||||||||||||||
| 78 | }, | ||||||||||||||
| 79 | 5 | ); | |||||||||||||
| 80 | |||||||||||||||
| 81 | 3 | ▶ | sub header_keys { | ||||||||||||
|
Subroutine
header_keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 82 | 3 | my $self = shift; | |||||||||||||
| 83 | |||||||||||||||
| 84 | 3 | return $self->name, 'charset'; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | |||||||||||||||
| 87 | 3 | ▶ | sub data { | ||||||||||||
|
Subroutine
data: called CC=9 SCAR=23.3
Pod
undocumented
| |||||||||||||||
| 88 | 3 | my ($self, $key, @args) = @_; | |||||||||||||
| 89 | |||||||||||||||
| 90 | 3 | ▶ | defined $key | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | or confess 'Undefined key'; | ||||||||||||||
| 92 | 3 | ▶ | my $value = @args ? $args[0] : (); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | 3 | ▶ | if ( $key eq 'Content-Type' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | return | ||||||||||||||
| 95 | @args | ||||||||||||||
| 96 | ? ( | ||||||||||||||
| 97 | $self->content_type( # set | ||||||||||||||
| 98 | ref $value eq 'HASH' | ||||||||||||||
| 99 | 2 | ▶ | ? $value->{$key} | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 100 | : $value | ||||||||||||||
| 101 | ) | ||||||||||||||
| 102 | ) | ||||||||||||||
| 103 | : $self->content_type; # get | ||||||||||||||
| 104 | } | ||||||||||||||
| 105 | 1 | ▶ | if ( $key eq 'charset' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | return | ||||||||||||||
| 107 | @args | ||||||||||||||
| 108 | ? ( | ||||||||||||||
| 109 | $self->charset( # set | ||||||||||||||
| 110 | ref $value eq 'HASH' | ||||||||||||||
| 111 | 1 | ▶ | ? $value->{$key} | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 112 | : $value | ||||||||||||||
| 113 | ) | ||||||||||||||
| 114 | ) | ||||||||||||||
| 115 | : $self->charset; # get | ||||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | confess "Unknown key $key"; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | |||||||||||||||
| 121 | 2 | ▶ | sub extract_msgstr { | ||||||||||||
|
Subroutine
extract_msgstr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 122 | 2 | my ($self, $msgstr_ref) = @_; | |||||||||||||
| 123 | |||||||||||||||
| 124 | 2 | ${$msgstr_ref} =~ s{ | |||||||||||||
| 125 | ^ | ||||||||||||||
| 126 | Content-Type : | ||||||||||||||
| 127 | \s* | ||||||||||||||
| 128 | ( [^;\n]*? ) ; | ||||||||||||||
| 129 | \s* | ||||||||||||||
| 130 | charset = ( \S* ) | ||||||||||||||
| 131 | \s* | ||||||||||||||
| 132 | $ | ||||||||||||||
| 133 | }{}xmsi; | ||||||||||||||
| 134 | 2 | $self->content_type($1); ## no critic (CaptureWithoutTest) | |||||||||||||
| 135 | 2 | $self->charset($2); ## no critic (CaptureWithoutTest) | |||||||||||||
| 136 | |||||||||||||||
| 137 | 2 | return; | |||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | 3 | ▶ | sub lines { | ||||||||||||
|
Subroutine
lines: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 141 | 3 | my $self = shift; | |||||||||||||
| 142 | |||||||||||||||
| 143 | 3 | return $self->format_line( | |||||||||||||
| 144 | '{name}: {content_type}; charset={charset}', | ||||||||||||||
| 145 | name => $self->name, | ||||||||||||||
| 146 | content_type => $self->content_type, | ||||||||||||||
| 147 | charset => $self->charset, | ||||||||||||||
| 148 | ); | ||||||||||||||
| 149 | } | ||||||||||||||
| 150 | |||||||||||||||
| 151 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 152 | |||||||||||||||
| 153 | # $Id: Utils.pm 602 2011-11-13 13:49:23Z steffenw $ | ||||||||||||||
| 154 | |||||||||||||||
| 155 | 5 | 1; | |||||||||||||