view release on metacpan or search on metacpan
CHANGES
CONTRIBUTING.md
lib/Apache2/API.pm
lib/Apache2/API/DateTime.pm
lib/Apache2/API/Query.pm
lib/Apache2/API/Request.pm
lib/Apache2/API/Request/Params.pm
lib/Apache2/API/Request/Upload.pm
lib/Apache2/API/Response.pm
lib/Apache2/API/Status.pm
Makefile.PL
MANIFEST This list of files
README
README.md
"Apache2::Reload" : "0",
"Apache2::Request" : "0",
"Apache2::RequestIO" : "0",
"Apache2::RequestRec" : "0",
"Apache2::RequestUtil" : "0",
"Apache2::Response" : "0",
"Apache2::ServerUtil" : "0",
"Apache2::SubRequest" : "0",
"Apache::Test" : "0",
"Cookie" : "v0.2.4",
"DateTime" : "1.57",
"DateTime::Format::Strptime" : "1.79",
"DateTime::TimeZone" : "2.51",
"DateTime::TimeZone::Catalog::Extend" : "v0.3.0",
"Encode" : "3.01",
"Exporter" : "5.70",
"HTTP::AcceptLanguage" : "0.02",
"JSON" : "4.03",
"JSON::XS" : "4.03",
"Module::Generic" : "v0.35.3",
"Regexp::Common" : "0",
"Scalar::Util" : "1.50",
"URI" : "0",
"URI::Escape" : "3.31",
Apache2::Reload: '0'
Apache2::Request: '0'
Apache2::RequestIO: '0'
Apache2::RequestRec: '0'
Apache2::RequestUtil: '0'
Apache2::Response: '0'
Apache2::ServerUtil: '0'
Apache2::SubRequest: '0'
Apache::Test: '0'
Cookie: v0.2.4
DateTime: '1.57'
DateTime::Format::Strptime: '1.79'
DateTime::TimeZone: '2.51'
DateTime::TimeZone::Catalog::Extend: v0.3.0
Encode: '3.01'
Exporter: '5.70'
HTTP::AcceptLanguage: '0.02'
JSON: '4.03'
JSON::XS: '4.03'
Module::Generic: v0.35.3
Regexp::Common: '0'
Scalar::Util: '1.50'
URI: '0'
URI::Escape: '3.31'
Makefile.PL view on Meta::CPAN
'Apache2::Response' => 0,
'Apache2::ServerUtil' => 0,
'Apache2::SubRequest' => 0,
'APR::Base64' => 0,
'APR::Pool' => 0,
'APR::Request::Apache2' => 0,
'APR::Request::Cookie' => 0,
'APR::Socket' => 0,
'APR::UUID' => 0,
'Cookie' => 'v0.2.4',
'DateTime' => '1.57',
'DateTime::Format::Strptime' => '1.79',
'DateTime::TimeZone' => '2.51',
'DateTime::TimeZone::Catalog::Extend' => 'v0.3.0',
# 'Devel::Confess' => 0,
'Encode' => '3.01',
'Exporter' => '5.70',
'HTTP::AcceptLanguage' => '0.02',
'JSON' => '4.03',
'JSON::XS' => '4.03',
'Module::Generic' => 'v0.35.3',
'Regexp::Common' => 0,
'Scalar::Util' => '1.50',
'URI' => 0,
A list of handlers configured to run at the child_exit phase:
@handlers = @{ $res->get_handlers( 'PerlChildExitHandler' ) || []};
gettext( 'string id' )
Get the localised version of the string passed as an argument.
This is supposed to be superseded by the package inheriting from
Apache2::API, if any.
header_datetime( DateTime object )
Given a DateTime object, this sets it to GMT time zone and set the
proper formatter (Apache2::API::DateTime) so that the stringification is
compliant with http headers standard.
is_perl_option_enabled
Checks if perl option is enabled in the Virtual Host and returns a
boolean value
json()
Returns a JSON object.
You can provide an optional hash or hash reference of properties to
Apache2 methods are designed to die upon error, whereas our model is
based on returning "undef" and setting an exception with
Module::Generic::Exception, because we believe that only the main
program should be in control of the flow and decide whether to interrupt
abruptly the execution, not some sub routines.
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
Apache2::API::DateTime, Apache2::API::Query, Apache2::API::Request,
Apache2::API::Request::Params, Apache2::API::Request::Upload,
Apache2::API::Response, Apache2::API::Status
Apache2::Request, Apache2::RequestRec, Apache2::RequestUtil
COPYRIGHT & LICENSE
Copyright (c) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
A list of handlers configured to run at the child\_exit phase:
@handlers = @{ $res->get_handlers( 'PerlChildExitHandler' ) || []};
## gettext( 'string id' )
Get the localised version of the string passed as an argument.
This is supposed to be superseded by the package inheriting from [Apache2::API](https://metacpan.org/pod/Apache2%3A%3AAPI), if any.
## header\_datetime( DateTime object )
Given a [DateTime](https://metacpan.org/pod/DateTime) object, this sets it to GMT time zone and set the proper formatter ([Apache2::API::DateTime](https://metacpan.org/pod/Apache2%3A%3AAPI%3A%3ADateTime)) so that the stringification is compliant with...
## is\_perl\_option\_enabled
Checks if perl option is enabled in the Virtual Host and returns a boolean value
## json()
Returns a JSON object.
You can provide an optional hash or hash reference of properties to enable or disable:
Given an object type, a method name and optional parameters, this attempts to call it, passing it whatever arguments were provided and return its return values.
Apache2 methods are designed to die upon error, whereas our model is based on returning `undef` and setting an exception with [Module::Generic::Exception](https://metacpan.org/pod/Module%3A%3AGeneric%3A%3AException), because we believe that only the ...
# AUTHOR
Jacques Deguest <`jack@deguest.jp`>
# SEE ALSO
[Apache2::API::DateTime](https://metacpan.org/pod/Apache2%3A%3AAPI%3A%3ADateTime), [Apache2::API::Query](https://metacpan.org/pod/Apache2%3A%3AAPI%3A%3AQuery), [Apache2::API::Request](https://metacpan.org/pod/Apache2%3A%3AAPI%3A%3ARequest), [Apache2:...
[Apache2::Request](https://metacpan.org/pod/Apache2%3A%3ARequest), [Apache2::RequestRec](https://metacpan.org/pod/Apache2%3A%3ARequestRec), [Apache2::RequestUtil](https://metacpan.org/pod/Apache2%3A%3ARequestUtil)
# COPYRIGHT & LICENSE
Copyright (c) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
SHA256 112361a52cebbb08848890de23c0802d3df842230da0eb8b897f7f5593518d60 CHANGES
SHA256 3c07e578226e8e4e1a8c503c31e081087393ec1757f132412c5e672fdd9347a9 CONTRIBUTING.md
SHA256 1408a92621df4cc58b15479cf88b72165713900e3f5103cafe90afd0ac6deffc MANIFEST
SHA256 cc699d9491b3c162355e9ca26ee5463a89b4a65154c7a3d58ca6cd5742498081 META.json
SHA256 fb0281ee7e03d09ada4963cb9f2d5dd7f61b9d2454279520599f51fa27238f3d META.yml
SHA256 661ead5534711eb84456ad72177128767430d5f3ca06a25998439c7d4bd358a1 Makefile.PL
SHA256 8008359cc47b83f5875ac6348ea919668d0f69cc00c6c00e7128e04751eefc1f README
SHA256 26088dbb25b6b29dd0f651c021fff8f65e3c37a265a5eaef4911c8926bf90307 README.md
SHA256 bc00728cc83093a020e2d450f07954db7a0655e5bee0872884da155d54f6ab6e lib/Apache2/API.pm
SHA256 c1250b55d088619976d5f4ea4322ba35eaea9ab1f55c245ffaa95e1a681f5afb lib/Apache2/API/DateTime.pm
SHA256 f89d09f44184b5f7ee28ab0a311b49cfb553f5c1836a552f926a80822bf9967d lib/Apache2/API/Query.pm
SHA256 420ddabf09cd55201b0a491cf37a8e20c771b560acf6421767fb5674f8139cdb lib/Apache2/API/Request.pm
SHA256 a297d2963e952b4c7dbde838ef5ea663af3157456d89681bb87291667f6a5528 lib/Apache2/API/Request/Params.pm
SHA256 aef7822897fe8af542218ec7d8ea0089d7bb1899f58b8b3182460773e421f8ad lib/Apache2/API/Request/Upload.pm
SHA256 517876872a6aaf2d3894981cc70e92effa4c92b119bea1fafd44023194c0874e lib/Apache2/API/Response.pm
SHA256 5c1545e2ba5b7a9a0ce51bda818423b18648f76b3e2465f3f4aded3bd0d554a5 lib/Apache2/API/Status.pm
SHA256 c57f25537b518b39d44842061a4ba8848c9e936a5305bbf1ed3eddab1d2a67e1 scripts/startup.pl
SHA256 6b386ddbdfddf10e3a4f822281faa57f0867f1fb253dba6920220a743a393d6a t/00.load.t
SHA256 8cd30ed713ba10037557de4c66ad15a3ccf2ce115281a0ebd21a9823e5c0c49e t/01.api.t
SHA256 d622123c4d83f5f1e1f56265bbbc00bc82a079c29757c64f5a78d1b9fbf68ab8 t/02.datetime.t
lib/Apache2/API.pm view on Meta::CPAN
# This gives a chance to return a localised version of our string to the user
sub gettext { return( $_[1] ); }
sub header_datetime
{
my $self = shift( @_ );
my $dt;
if( @_ )
{
return( $self->error( "Date time provided (", ( $_[0] // 'undef' ), ") is not an object." ) ) if( !Scalar::Util::blessed( $_[0] ) );
return( $self->error( "Object provided (", ref( $_[0] ), ") is not a DateTime object." ) ) if( !$_[0]->isa( 'DateTime' ) );
$dt = shift( @_ );
}
$dt = DateTime->now if( !defined( $dt ) );
my $fmt = Apache2::API::DateTime->new;
$dt->set_formatter( $fmt );
return( $dt );
}
sub is_perl_option_enabled { return( shift->_try( 'request', 'is_perl_option_enabled', @_ ) ); }
# We return a new object each time, because if we cached it, some routine might set the utf8 bit flagged on while some other would not want it
sub json
{
my $self = shift( @_ );
lib/Apache2/API.pm view on Meta::CPAN
A list of handlers configured to run at the child_exit phase:
@handlers = @{ $res->get_handlers( 'PerlChildExitHandler' ) || []};
=head2 gettext( 'string id' )
Get the localised version of the string passed as an argument.
This is supposed to be superseded by the package inheriting from L<Apache2::API>, if any.
=head2 header_datetime( DateTime object )
Given a L<DateTime> object, this sets it to GMT time zone and set the proper formatter (L<Apache2::API::DateTime>) so that the stringification is compliant with HTTP headers standard.
=head2 is_perl_option_enabled
Checks if perl option is enabled in the Virtual Host and returns a boolean value
=head2 json
Returns a JSON object.
You can provide an optional hash or hash reference of properties to enable or disable:
lib/Apache2/API.pm view on Meta::CPAN
=head2 API CORE MODULES
L<Apache2::RequestIO>, L<Apache2::RequestRec>
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 SEE ALSO
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) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
lib/Apache2/API/DateTime.pm view on Meta::CPAN
# -*- perl -*-
##----------------------------------------------------------------------------
## Apache2 API Framework - ~/lib/Apache2/API/DateTime.pm
## Version v0.1.2
## Copyright(c) 2023 DEGUEST Pte. Ltd.
## Author: Jacques Deguest <jack@deguest.jp>
## Created 2023/05/30
## Modified 2024/09/04
## All rights reserved
##
##
## This program is free software; you can redistribute it and/or modify it
## under the same terms as Perl itself.
##----------------------------------------------------------------------------
package Apache2::API::DateTime;
BEGIN
{
use strict;
use warnings;
use parent qw( Module::Generic );
use vars qw( $VERSION );
use APR::Date;
use DateTime;
our $VERSION = 'v0.1.2';
};
use strict;
use warnings;
sub format_datetime
{
my( $self, $dt ) = @_;
$dt = DateTime->now unless( defined( $dt ) );
$dt = $dt->clone->set_time_zone( 'GMT' );
return( $dt->strftime( '%a, %d %b %Y %H:%M:%S GMT' ) );
}
# Using APR::Date::parse_http instead?
# <https://perl.apache.org/docs/2.0/api/APR/Date.html#toc_C_parse_http_>
sub parse_date
{
my $self = shift( @_ );
my $date = shift( @_ ) || return( $self->error( "No date to parse was provided." ) );
lib/Apache2/API/DateTime.pm view on Meta::CPAN
$dt = $self->_parse_timestamp( $date );
return( $self->pass_error ) if( !defined( $dt ) );
return( $dt );
}
else
{
# try-catch
local $@;
eval
{
$dt = DateTime->from_epoch( epoch => $time );
};
if( $@ )
{
return( $self->error( "Error instantiating a DateTime object with the epoch value equivalent of the date provided $date: $@" ) );
}
return( $dt );
}
}
sub str2datetime { return( shift->parse_datetime( @_ ) ); }
sub str2time
{
my $self = shift( @_ );
my $dt = $self->str2datetime( @_ );
return if( !defined( $dt ) );
return( $dt->epoch );
}
sub time2datetime
{
my $self = shift( @_ );
my $time = shift( @_ );
$time = time() unless( defined( $time ) );
my $dt = DateTime->from_epoch( epoch => $time );
$dt->set_formatter( $self );
return( $dt );
}
sub time2str
{
my $self = shift( @_ );
my $dt = $self->time2datetime( @_ );
$dt->set_formatter( $self );
my $str = "$dt";
lib/Apache2/API/DateTime.pm view on Meta::CPAN
# NOTE: sub THAW is inherited
1;
# NOTE: POD
__END__
=encoding utf8
=head1 NAME
Apache2::API::DateTime - HTTP DateTime Manipulation and Formatting
=head1 SYNOPSIS
use Apache2::API::DateTime;
my $d = Apache2::API::DateTime->new( debug => 3 );
my $dt = DateTime->now;
$dt->set_formatter( $d );
print( "$dt\n" );
## will produce
Sun, 15 Dec 2019 15:32:12 GMT
my( @parts ) = $d->parse_date( $date_string );
my $datetime_object = $d->str2datetime( $date_string );
$datetime_object->set_formatter( $d );
my $timestamp_in_seconds = $d->str2time( $date_string );
my $datetime_object = $d->time2datetime( $timestamp_in_seconds );
my $datetime_string = $d->time2str( $timestamp_in_seconds );
=head1 VERSION
v0.1.2
=head1 DESCRIPTION
This module contains methods to create and manipulate datetime representation from and to L<DateTime> object or unix timestamps.
When using it as a formatter to a L<DateTime> object, this will make sure it is properly formatted for its use in HTTP headers and cookies.
=head1 METHODS
=head2 new
This initiates the package and take the following parameters:
=over 4
=item * C<debug>
Optional. If set with a positive integer, this will activate verbose debugging message
=back
=head2 format_datetime
Provided a L<DateTime> object, this returns a HTTP compliant string representation, such as:
Sun, 15 Dec 2019 15:32:12 GMT
that can be used in HTTP headers and cookies' expires property as per rfc6265.
=head2 parse_date
Given a datetime string, this returns, in list context, a list of day, month, year, hour, minute, second and time zone or an iso 8601 datetime string in scalar context.
This is used by the method L</str2datetime>
=head2 parse_datetime
Provided with a date string, and this will parse it and return a L<DateTime> object, or sets an L<error|Module::Generic/error> and return C<undef> or an empty list depending on the context.
=head2 str2datetime
Given a string that looks like a date, this will parse it and return a L<DateTime> object.
=head2 str2time
Given a string that looks like a date, this returns its representation as a unix timestamp in second since epoch.
In the background, it calls L</str2datetime> for parsing.
=head2 time2datetime
Given a unix timestamp in seconds since epoch, this returns a L<DateTime> object.
=head2 time2str
Given a unix timestamp in seconds since epoch, this returns a string representation of the timestamp suitable for HTTP headers and cookies. The format is like C<Sat, 14 Dec 2019 22:12:30 GMT>
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 SEE ALSO
L<DateTime>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
=cut
lib/Apache2/API/Request.pm view on Meta::CPAN
use APR::Pool ();
use APR::Request ();
use APR::Socket ();
use APR::SockAddr ();
use APR::Request::Cookie;
use APR::Request::Apache2;
# For subnet_of() method
use APR::IpSubnet ();
use Apache2::API::Request::Params;
use Apache2::API::Request::Upload;
use Apache2::API::DateTime;
use Apache2::API::Query;
use Apache2::API::Status;
use Cookie::Jar;
use DateTime;
use Encode ();
use File::Which ();
use HTTP::AcceptLanguage;
use JSON ();
use Module::Generic::HeaderValue;
use Scalar::Util;
use URI;
use URI::Escape;
use Want;
our $VERSION = 'v0.2.1';
lib/Apache2/API/Request.pm view on Meta::CPAN
};
if( $@ )
{
return( $self->error({ code => Apache2::Const::HTTP_BAD_REQUEST, message => "Error while decoding payload received from http client: $@" }) );
}
$self->{data} = $payload;
$self->{_data_processed}++;
return( $payload );
}
sub datetime { return( Apache2::API::DateTime->new( debug => shift->debug ) ); }
sub decode
{
my $self = shift( @_ );
return( APR::Request::decode( shift( @_ ) ) );
}
# Do not track: 1 or 0
sub dnt { return( shift->env( 'HTTP_DNT', @_ ) ); }
lib/Apache2/API/Request.pm view on Meta::CPAN
sub request { return( shift->_set_get_object_without_init( 'request', 'Apache2::Request', @_ ) ); }
sub request_scheme { return( shift->env( 'REQUEST_SCHEME', @_ ) ); }
# sub request_time { return( shift->request->request_time ); }
sub request_time
{
my $self = shift( @_ );
my $t = $self->request->request_time;
my $dt = DateTime->from_epoch( epoch => $t );
# An Apache2::API::DateTime object
my $fmt = $self->datetime;
$dt->set_formatter( $fmt );
return( $dt );
}
sub request_uri { return( shift->env( 'REQUEST_URI', @_ ) ); }
sub requires { return( shift->_try( 'request', 'requires' ) ); }
sub satisfies { return( shift->_try( 'request', 'satisfies' ) ); }
lib/Apache2/API/Request.pm view on Meta::CPAN
my $addr = $req->remote_addr;
my $host = $req->remote_host;
my $string = $req->remote_ip;
my $port = $req->remote_port;
$req->reply( Apache2::Const::FORBIDDEN => { message => "Get away" } );
# Apache2::RequestRec
my $r = $req->request;
my $scheme = $req->request_scheme;
# DateTime object
my $dt = $req->request_time;
my $uri = $req->request_uri;
my $filename = $req->script_filename;
my $name = $req->script_name;
my $uri = $req->script_uri;
# Apache2::ServerUtil object
my $server = $req->server;
my $addr = $req->server_addr;
my $admin = $req->server_admin;
my $hostname = $req->server_hostname;
lib/Apache2/API/Request.pm view on Meta::CPAN
# package inheriting from Apache2::API
PerlResponseHandler My::API
# 2Mb upload limit
PerlSetVar PAYLOAD_MAX_SIZE 2097152
</Directory>
This is just an example and not a recommandation. Your mileage may vary.
=head2 datetime
Returns a new L<Apache2::API::DateTime> object, which is used to parse and format dates for HTTP.
See L<Apache2::API/parse_datetime> and L<Apache2::API/format_datetime>
=head2 decode
Given a url-encoded string, this returns the decoded string, by calling L<APR::Request/decode>
This uses L<APR::Request> XS method.
See also L<rfc3986|https://datatracker.ietf.org/doc/html/rfc3986>
lib/Apache2/API/Request.pm view on Meta::CPAN
=head2 id
Returns the connection id; unique at any point in time, by calling L<Apache2::Connection/id>.
See L<Apache2::Connection> for more information.
This is the same as L</connection_id>
=head2 if_modified_since
Returns the value of the HTTP header If-Modified-Since as a C<DateTime> object.
If no such header exists, it returns C<undef> or an empty list depending on the context.
=head2 if_none_match
Sets or gets the value of the HTTP header C<If-None-Match>
See also L</headers>
=head2 input_filters
lib/Apache2/API/Request.pm view on Meta::CPAN
It can take as argument, only a key and it will then retrieve the corresponding value, or it can take a key and value pair to set them using L<Apache2::API::Request::Params/param>
If the value is an array, this will set multiple entry of the key for each value provided.
This uses Apache L<APR::Table> and works for both C<POST> and C<GET> methods.
If the methods received was a C<GET> method, this method returns the value of the L</query> method instead.
=head2 parse_date
Alias to L<Apache2::API::DateTime/parse_date>
=head2 path
Get the value for the environment variable C<PATH>
See also L</env>
=head2 path_info
my $path_info = $req->path_info();
lib/Apache2/API/Request.pm view on Meta::CPAN
Returns the embedded L<Apache2::RequestRec> object provided initially at object instantiation.
=head2 request_scheme
Gets or sets the environment variable C<REQUEST_SCHEME>
=head2 request_time
Read-only.
Returns the time when the request started as a L<DateTime> object with L<Apache2::API::DateTime> as the formatter.
=head2 request_uri
This returns the current value for the environment variable C<REQUEST_URI>, or set its value if an argument is provided.
The uri provided by this environment variable include the path info if any.
For example, assuming you have a cgi residing in C</cgi-bin/prog.cgi> and it is called with the path info C</some/value>, the value returned would then be C</cgi-bin/prog.cgi/some/value>
=head2 requires
lib/Apache2/API/Request.pm view on Meta::CPAN
This method is also handy when you extend the HTTP protocol and add new response codes. For example you could invent a new error code and tell Apache to use that in the response like so:
$req->status_line( "499 We have been FooBared" );
return( Apache2::Const::OK );
Here 499 is the new response code, and We have been FooBared is the custom response message.
=head2 str2datetime
Alias to L<Apache2::API::DateTime/str2datetime>
=head2 str2time
Alias to L<Apache2::API::DateTime/str2time>
=head2 subnet_of
Provided with an ip address (v4 or v6), and optionally a subnet mask, and this will return a boolean value indicating if the current connection ip address is part of the provided subnet.
The mask can be a string or a number of bits.
It uses L<APR::IpSubnet> and performs the test using the object from L<APR::SockAddr> as provided with L</remote_addr>
my $ok = $req->subnet_of( '127.0.0.1' );
lib/Apache2/API/Request.pm view on Meta::CPAN
my $request = $req->the_request();
my $old_request = $req->uri( $new_request );
Get or set the first HTTP request header as a string by calling L<Apache2::RequestRec/the_request>. For example:
GET /foo/bar/my_path_info?args=3 HTTP/1.0
=head2 time2datetime
Alias to L<Apache2::API::DateTime/time2datetime>
=head2 time2str
Alias to L<Apache2::API::DateTime/time2str>
=head2 type
Returns the content type of the request received. This value is set at object initiation phase.
So for example, if the HTTP request C<Content-type> is
Content-Type: application/json; charset=utf-8
Then, L</type> would return C<application/json>
t/00.load.t view on Meta::CPAN
use warnings;
use lib './lib';
use Test2::V0;
}
# To build the list of modules:
# find ./lib -type f -name "*.pm" -print | xargs perl -lE 'my @f=sort(@ARGV); for(@f) { s,./lib/,,; s,\.pm$,,; s,/,::,g; substr( $_, 0, 0, q{use ok( ''} ); $_ .= q{'' );}; say $_; }'
BEGIN
{
use ok( 'Apache2::API' );
use ok( 'Apache2::API::DateTime' );
use ok( 'Apache2::API::Query' );
use ok( 'Apache2::API::Request' );
use ok( 'Apache2::API::Request::Params' );
use ok( 'Apache2::API::Request::Upload' );
use ok( 'Apache2::API::Response' );
use ok( 'Apache2::API::Status' );
};
done_testing();
t/02.datetime.t view on Meta::CPAN
BEGIN
{
use strict;
use warnings;
use lib './lib';
use open ':std' => ':utf8';
use vars qw( $DEBUG );
use Test2::V0;
# 2021-11-1T167:12:10+0900
use Test::Time time => 1635754330;
use ok( 'Apache2::API::DateTime' );
use ok( 'DateTime' ) || bail_out( "No DateTime module installed" );
our $DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;
require( "./t/env.pl" ) if( -e( "t/env.pl" ) );
};
use strict;
use warnings;
my $fmt = Apache2::API::DateTime->new;
isa_ok( $fmt, 'Apache2::API::DateTime' );
# To generate this list:
# perl -lnE '/^sub (?!init|[A-Z]|_)/ and say "can_ok( \$fmt, \''", [split(/\s+/, $_)]->[1], "\'' );"' ./lib/Apache2/API/DateTime.pm
can_ok( $fmt, 'format_datetime' );
can_ok( $fmt, 'parse_date' );
can_ok( $fmt, 'parse_datetime' );
can_ok( $fmt, 'str2datetime' );
can_ok( $fmt, 'str2time' );
can_ok( $fmt, 'time2datetime' );
can_ok( $fmt, 'time2str' );
my $dt = DateTime->now;
$dt->set_formatter( $fmt );
is( $dt->stringify, 'Mon, 01 Nov 2021 08:12:10 GMT', 'format_datetime' );
my @tests = (
['Mon, 01 Nov 2021 08:12:10 GMT','2021-11-01T08:12:10','rfc822/rfc1123 format'],
['Monday, 01-Nov-21 08:12:10 GMT','2021-11-01T08:12:10','rfc1036'],
['Mon Nov 1 08:12:10 2021','2021-11-01T08:12:10','ANSI C asctime'],
['01 Nov 2021 08:12:10 GMT','2021-11-01T08:12:10','rfc7231'],
['2021-11-01T08:12:10','2021-11-01T08:12:10','iso8601'],
['2021-11-01 08:12:10','2021-11-01T08:12:10','iso8601'],
);
t/lib/Test/Apache2/API/Request.pm view on Meta::CPAN
);
} }) ); }
# NOTE: special processing
sub query_string { return( shift->_test({ method => 'query_string', expect => 'foo=bar&lang=ja-JP&q=%E6%9C%80%E9%AB%98%E3%81%A0%EF%BC%81' }) ); }
sub referer { return( shift->_test({ method => 'referer', expect => 'https://example.org/some/where.html' }) ); }
sub remote_addr { return( shift->_test({ method => 'remote_addr', expect => 'APR::SockAddr', type => 'isa' }) ); }
sub request_time { return( shift->_test({ method => 'request_time', expect => 'DateTime', type => 'isa' }) ); }
# requires
# satisfies
# script_filename
# script_name
# script_uri
# script_url
# Apache2::ServerUtil->server
sub server { return( shift->_test({ method => 'server', expect => 'Apache2::ServerRec', type => 'isa' }) ); }