Apache2-API

 view release on metacpan or  search on metacpan

lib/Apache2/API/DateTime.pm  view on Meta::CPAN

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>

t/06.apr1.t  view on Meta::CPAN


my $have_sha256_crypt = _crypt_supports( qr/^\$5\$/, _sha256_setting( $sha_rounds, $salt16 ) );
my $have_sha512_crypt = _crypt_supports( qr/^\$6\$/, _sha512_setting( $sha_rounds, $salt16 ) );
my $have_sha_fallback = _have_module( 'Crypt::Passwd::XS' );

subtest 'format & alphabet' => sub
{
    # random salt
    my $ht = $api->htpasswd( 'secret', create => 1 );
    my $h = $ht->hash;
    like( $h, qr/\A\$apr1\$[.\/0-9A-Za-z]{1,8}\$[.\/0-9A-Za-z]{22}\z/, 'hash format looks right' );

    my( $salt, $body ) = $h =~ m/\A\$apr1\$([.\/0-9A-Za-z]{1,8})\$([.\/0-9A-Za-z]{22})\z/;
    ok( length( $salt ) >= 1 && length( $salt ) <= 8, 'salt length within [1..8]' );
    ok( length( $body ) == 22, 'encoded body is 22 chars' );

    my $alphabet = qr/[.\/0-9A-Za-z]/;
    ok( ( $salt =~ /\A$alphabet+\z/ ), 'salt chars in alphabet' );
    ok( ( $body =~ /\A$alphabet+\z/ ), 'body chars in alphabet' );
};



( run in 0.628 second using v1.01-cache-2.11-cpan-39bf76dae61 )