Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API/Headers/AcceptCommon.pm view on Meta::CPAN
Given an array reference of server-supported tokens, returns the best match as a string, based on quality and specificity.
If none could be found, it returns an empty string, or if an error occurred, it sets an error that can be retrieved with the L<error method|Module::Generic/error>, and it returns C<undef> in scalar context, or an empty list in list context.
Semantics:
=over 4
=item * If no usable header was provided, the first entry in the array reference of supported tokens is returned.
=item * For each client preference (sorted by C<q> desc), exact matches are preferred over partial ones (as defined by the subclass), and then by specificity (subclasses implement C<_specificity>).
=item * Wildcards are treated as I<candidates> with the lowest specificity. They never preempt an equal-C<q> exact match.
=item * Legacy tie-breaking is available, see L</MATCH PRIORITY MODE>.
=back
=head2 preferences
Read-only.
Returns an array reference of the client tokens, sorted by decreasing quality weight (C<q>) as submitted upon the HTTP request, with duplicates removed (keeping highest C<q>). Always returns an array reference (even when cached).
So, for example:
my $accept = Apache2::API::Headers::Accept->new( 'text/html;q=0.9,application/json' );
my $prefs = $accept->preferences; # ['application/json', 'text/html']
If an error occurred, it sets an error that can be retrieved with the L<error method|Module::Generic/error>, and it returns C<undef> in scalar context, or an empty list in list context.
=head1 MATCH PRIORITY MODE
Two policies are supported for tie-breaking when several tokens have the same C<q>. You can choose per subclass:
=over 4
=item * Modern (default): tie favors header order (clientâs order) and specificity.
=item * Legacy C<0.01> style: set the package variable C<Apache2::API::Headers::Accept::MATCH_PRIORITY_0_01_STYLE = 1> or C<Apache2::API::Headers::AcceptLanguage::MATCH_PRIORITY_0_01_STYLE = 1>. At each equal-C<q> bucket, the choice follows the I<ser...
=back
=head1 DIAGNOSTICS
This module registers warnings in category C<Apache2::API>. With debugging enabled (via L<Module::Generic>), you will see trace messages such as parsing steps and why a candidate was chosen.
=head1 THREAD SAFETY
All state is per object; no shared mutable globals. Thus, this module is safe to use in threads.
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 SEE ALSO
L<Apache2::API::Headers::Accept>, L<Apache2::API::Headers::AcceptLanguage>, L<Module::Generic::HeaderValue>, RFC 7231, RFC 9110.
L<Apache2::API::DateTime>, L<Apache2::API::Query>, L<Apache2::API::Request>, L<Apache2::API::Request::Params>, L<Apache2::API::Request::Upload>, L<Apache2::API::Response>, L<Apache2::API::Status>
L<Apache2::Request>, L<Apache2::RequestRec>, L<Apache2::RequestUtil>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2025 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
=cut
( run in 0.935 second using v1.01-cache-2.11-cpan-5b529ec07f3 )