File Coverage

lib/HTTP/Promise/Headers/AcceptLanguage.pm
Criterion Covered Total %
statement 23 23 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/AcceptLanguage.pm
3             ## Version v0.1.0
4             ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2022/05/06
7             ## Modified 2022/05/06
8             ## All rights reserved.
9             ##
10             ##
11             ## This program is free software; you can redistribute it and/or modify it
12             ## under the same terms as Perl itself.
13             ##----------------------------------------------------------------------------
14             package HTTP::Promise::Headers::AcceptLanguage;
15             BEGIN
16             {
17 3     3   3165 use strict;
  3         6  
  3         90  
18 3     3   24 use warnings;
  3         13  
  3         100  
19 3     3   15 use warnings::register;
  3         5  
  3         376  
20 3     3   17 use parent qw( HTTP::Promise::Headers::Accept );
  3         6  
  3         12  
21 3     3   239 our $VERSION = 'v0.1.0';
22             };
23              
24 3     3   15 use strict;
  3         16  
  3         66  
25 3     3   14 use warnings;
  3         6  
  3         282  
26              
27             sub init
28             {
29 3     3 1 5740 my $self = shift( @_ );
30 3 50       30 $self->SUPER::init( @_ ) || return( $self->pass_error );
31 3         32 $self->_field_name( 'Accept-Language' );
32 3         2448 return( $self );
33             }
34              
35             1;
36             # NOTE: POD
37             __END__
38              
39             =encoding utf-8
40              
41             =head1 NAME
42              
43             HTTP::Promise::Headers::AcceptLanguage - Accept-Language Header Field
44              
45             =head1 SYNOPSIS
46              
47             use HTTP::Promise::Headers::AcceptLanguage;
48             my $ac = HTTP::Promise::Headers::AcceptLanguage->new ||
49             die( HTTP::Promise::Headers::AcceptLanguage->error, "\n" );
50             my $ac = HTTP::Promise::Headers::AcceptLanguage->new( 'fr-FR, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5' ) ||
51             die( HTTP::Promise::Headers::AcceptLanguage->error, "\n" );
52             $ac->add( fr' );
53             $ac->add( 'ja-JP' => 0.7 );
54             $h->accept( $ac->as_string ); Accept: fr, ja-JP;q=0.7
55             # or
56             $h->accept( "$ac" );
57             my $qv_elements = $ac->elements;
58             my $obj = $ac->get( 'ja-JP' );
59             # change the weight
60             $obj->value( 0.3 );
61             $ac->remove( 'fr' );
62             my $sorted_objects = $ac->sort;
63             my $asc_sorted = $ac->sort(1);
64             # Returns a Module::Generic::Array object
65             my $ok = $ac->match( [qw( fr ja-JP en en-GB en-US )] );
66              
67             =head1 VERSION
68              
69             v0.1.0
70              
71             =head1 DESCRIPTION
72              
73             This class inherits all its features from L<HTTP::Promise::Headers::Accept>
74              
75             The following description is taken from Mozilla documentation.
76              
77             Accept-Language: da, en-gb;q=0.8, en;q=0.7
78             Accept-Language: fr-FR, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5
79              
80             =head1 METHODS
81              
82             See L<HTTP::Promise::Headers::Accept>
83              
84             =head1 AUTHOR
85              
86             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
87              
88             =head1 SEE ALSO
89              
90             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language>
91              
92             L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception>
93              
94             L<HTTP::AcceptLanguage>
95              
96             =head1 COPYRIGHT & LICENSE
97              
98             Copyright(c) 2022 DEGUEST Pte. Ltd.
99              
100             All rights reserved.
101              
102             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
103              
104             =cut