NAME
HTTP::Tiny - Mock HTTP::Tiny class
SYNOPSIS
use lib qw{ inc/Mock };
use HTTP::Tiny;
...
DESCRIPTION
This Perl class mocks whatever portion of the HTTP::Tiny interface is needed by Test::Pod::LinkCheck::Lite. It is private to that distribution, and may change or be revoked without notice. Documentation is for the benefit of the author.
It works by reading a Storable file which contains a hash mapping URLs to desired status codes. When a request is made, the URL is looked up in the hash, and a respose with the requested status is returned. If the URL is not found, the status is 404.
METHODS
This class supports the following public methods:
new
my $ua = HTTP::Tiny->new();
This static method instantiates the object. Optional arguments may be passed as name/value pairs. The only supported argument is
- agent
-
This argument specifies the user agent string. If it ends in a space the default user agent string is appended.
- fn
-
This argument specifies the file to read for the desired statuses. The default is t/data/_http/status. This argument is not recognized by the real HTTP::Tiny.
agent
my $user_agent_string = ua->agent();
This method retrieves (but does not set) the user agent string.
can_ssl
my $ok = HTTP::Tiny->can_ssl();
my ( $ok, $reason ) = HTTP::Tiny->can_ssl();
If called in scalar context, this static method returns a true value if IO::Socket::SSL is available and a false value otherwise. In list context, if $ok is false $resource will contain the reason why not.
The HTTP::Tiny functionality when the invocant is an object is not provided.
head
my $resp = $ua->head( $url );
This method simulates a HEAD request. It simply delegates to the request() method.
request
my $resp = $ua->request( $method => $url );
This method simulates executing the given method against the given url. The $method is actually ignored. The status of the request is derived by reading the status file (see argument fn to new()) and looking up the given URL. If it is found, the specified status is used. Otherwise the status is 404.
All standard fields in the response hash are populated. However, all have static values except for the following:
- reason
-
If HTTP::Status can be loaded, this will be the reason message appropriate to the code. Otherwise it will be
'OK'for a success code or'Failed'otherwise. - status
-
The status of the request.
- success
-
True if the status is 2xx; false otherwise.
- url
-
The requested URL.
SEE ALSO
HTTP::Tiny (the real one).
SUPPORT
Support is by the author. Please file bug reports at https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Pod-LinkCheck-Lite, https://github.com/trwyant/perl-Test-Pod-LinkCheck-Lite/issues, or in electronic mail to the author.
AUTHOR
Thomas R. Wyant, III wyant at cpan dot org
COPYRIGHT AND LICENSE
Copyright (C) 2019-2024 by Thomas R. Wyant, III
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.