NAME
HTTP::API::Core::RateLimit - Normalized HTTP API rate-limit metadata
DESCRIPTION
Represents rate-limit information parsed from the RateLimit-Limit, RateLimit-Remaining, and RateLimit-Reset header family used by earlier IETF rate-limit drafts, plus the widely-used X-RateLimit-* family. Retry-After is also captured.
METHODS
new
my $quota = HTTP::API::Core::RateLimit->new(
remaining => 0,
reset => 10,
);
Constructs normalized metadata directly. Numeric fields accept non-negative decimal numbers or undef. resource and source are scalar values or undef.
from_headers
my $quota = HTTP::API::Core::RateLimit->from_headers($headers);
Parses a header hash reference using case-insensitive names. Missing or undefined headers yield unknown metadata. Repeated values are accepted when identical; conflicting values are treated as unknown. For limit, remaining, used and resource, a present RateLimit-* field takes precedence over its legacy X-RateLimit-* counterpart even if the standard value cannot be parsed.
retry_after
Numeric Retry-After delay when available. HTTP-date parsing belongs to the client's retry policy rather than this accessor.
source
Returns ratelimit or x-ratelimit when the corresponding limit, remaining or reset header family is present; otherwise undef. The standard family takes precedence.
as_hash
Returns a new hash reference containing the eight normalized fields, including undefined values.
limit, remaining, used, resource
Normalized quota metadata when present.
reset
Seconds until reset from RateLimit-Reset.
reset_epoch
UTC epoch reset timestamp from X-RateLimit-Reset.
wait_seconds
Returns the preferred delay before retrying. Retry-After takes precedence, then RateLimit-Reset, then X-RateLimit-Reset converted from epoch time. An elapsed reset timestamp yields zero; unavailable delay information yields undef. Pass now => $epoch to use a specified non-negative epoch rather than the current time.
exhausted
True when a numeric remaining value is present and is zero or less.