Apache2-API

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        my $utf8 = $api->encode_utf8( $data );
        my $uuid = $api->generate_uuid;
        my $auth = $api->get_auth_bearer;
        my $handlers = $api->get_handlers;
        my $dt = $api->header_datetime( $http_datetime );
        my $bool = $api->is_perl_option_enabled;
        # JSON object
        my $json = $api->json( pretty => 1, sorted => 1, relaxed => 1 );
        my $lang = $api->lang( 'en_GB' );
        # en_GB
        my $lang = $api->lang_unix;
        # en-GB
        my $lang = $api->lang_web;
        $api->log_error( "Oops" );
        $api->print( @some_data );
        $api->push_handlers( $name => $code_reference );
        return( $api->reply( Apache2::Const::HTTP_OK => {
            message => "All good!",
            # arbitrary property
            client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
            # special property

README  view on Meta::CPAN


    Each property corresponds to one that is supported by JSON

    It also supports "ordered", "order" and "sort" as an alias to
    "canonical"

  lang( $string )
    Set or get the language for the API. This would typically be the HTTP
    preferred language.

  lang_unix( $string )
    Given a language, this returns a language code formatted the unix way,
    ie en-GB would become en_GB

  lang_web( $string )
    Given a language, this returns a language code formatted the web way, ie
    en_GB would become en-GB

  log
        $api->log->emerg( "Urgent message." );
        $api->log->alert( "Alert!" );
        $api->log->crit( "Critical message." );

README.md  view on Meta::CPAN

    my $utf8 = $api->encode_utf8( $data );
    my $uuid = $api->generate_uuid;
    my $auth = $api->get_auth_bearer;
    my $handlers = $api->get_handlers;
    my $dt = $api->header_datetime( $http_datetime );
    my $bool = $api->is_perl_option_enabled;
    # JSON object
    my $json = $api->json( pretty => 1, sorted => 1, relaxed => 1 );
    my $lang = $api->lang( 'en_GB' );
    # en_GB
    my $lang = $api->lang_unix;
    # en-GB
    my $lang = $api->lang_web;
    $api->log_error( "Oops" );
    $api->print( @some_data );
    $api->push_handlers( $name => $code_reference );
    return( $api->reply( Apache2::Const::HTTP_OK => {
        message => "All good!",
        # arbitrary property
        client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
        # special property

README.md  view on Meta::CPAN

    my $J = $api->json( pretty => 1, relaxed => 1 );

Each property corresponds to one that is supported by [JSON](https://metacpan.org/pod/JSON)

It also supports `ordered`, `order` and `sort` as an alias to `canonical`

## lang( $string )

Set or get the language for the API. This would typically be the HTTP preferred language.

## lang\_unix( $string )

Given a language, this returns a language code formatted the unix way, ie en-GB would become en\_GB

## lang\_web( $string )

Given a language, this returns a language code formatted the web way, ie en\_GB would become en-GB

## log

    $api->log->emerg( "Urgent message." );
    $api->log->alert( "Alert!" );
    $api->log->crit( "Critical message." );

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

            warn( "Unknown JSON option '${opt}'\n" ) if( $self->_warnings_is_enabled );
            next;
        };
        $ref->( $j, $opts->{ $opt } );
    }
    return( $j );
}

sub lang { return( shift->_set_get_scalar( 'lang', @_ ) ); }

sub lang_unix
{
    my $self = shift( @_ );
    my $lang = $self->{lang};
    $lang =~ tr/-/_/;
    return( $lang );
}

sub lang_web
{
    my $self = shift( @_ );

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

    my $guess_preferred_locale = sub
    {
        my $locale = shift( @_ );
        if( !defined( $locale ) )
        {
            $locale = $req->preferred_language( Apache2::API::Status->supported_languages );
        }

        if( defined( $locale ) )
        {
            # Make sure we are dealing with unix style language code
            $locale =~ tr/-/_/;
            if( length( $locale ) == 2 )
            {
                $locale = Apache2::API::Status->convert_short_lang_to_long( $locale );
            }
            # We have something weird, like maybe eng?
            elsif( $locale !~ /^[a-z]{2}_[A-Z]{2}$/ )
            {
                $locale = Apache2::API::Status->convert_short_lang_to_long( substr( $locale, 0, 2 ) );
            }

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

    my $utf8 = $api->encode_utf8( $data );
    my $uuid = $api->generate_uuid;
    my $auth = $api->get_auth_bearer;
    my $handlers = $api->get_handlers;
    my $dt = $api->header_datetime( $http_datetime );
    my $bool = $api->is_perl_option_enabled;
    # JSON object
    my $json = $api->json( pretty => 1, sorted => 1, relaxed => 1 );
    my $lang = $api->lang( 'en_GB' );
    # en_GB
    my $lang = $api->lang_unix;
    # en-GB
    my $lang = $api->lang_web;
    $api->log_error( "Oops" );
    $api->print( @some_data );
    $api->push_handlers( $name => $code_reference );
    return( $api->reply( Apache2::Const::HTTP_OK => {
        message => "All good!",
        # arbitrary property
        client_id => "efe4bcf3-730c-4cb2-99df-25d4027ec404",
        # special property

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

    my $J = $api->json( pretty => 1, relaxed => 1 );

Each property corresponds to one that is supported by L<JSON>

It also supports C<ordered>, C<order> and C<sort> as an alias to C<canonical>

=head2 lang( $string )

Set or get the language for the API. This would typically be the HTTP preferred language.

=head2 lang_unix( $string )

Given a language, this returns a language code formatted the unix way, ie en-GB would become en_GB

=head2 lang_web( $string )

Given a language, this returns a language code formatted the web way, ie en_GB would become en-GB

=head2 log

    $api->log->emerg( "Urgent message." );
    $api->log->alert( "Alert!" );
    $api->log->crit( "Critical message." );

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

	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

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

=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

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


sub preferred_language
{
    my $self = shift( @_ );
    my $ok_langs = [];
    if( @_ )
    {
        return( $self->error( "I was expecting a list of supported languages as array reference, but instead I received this '", join( "', '", @_ ), "'." ) ) if( !$self->_is_array( $_[0] ) );
        # Make a copy
        $ok_langs = [ @{$_[0]} ];
        # Make sure the languages provided are in web format (e.g. en-GB), not unix format (e.g. en_GB)
        for( my $i = 0; $i < scalar( @$ok_langs ); $i++ )
        {
            $ok_langs->[ $i ] =~ tr/_/-/;
        }
    }
    else
    {
        return( $self->error( "No supported languages list was provided as array reference." ) );
    }
    # No supported languages was provided

lib/Apache2/API/Request/Upload.pm  view on Meta::CPAN

=head2 length

Returns the size of the param's file-upload content.

May also be called as B<size>

=head2 link

Provided with a file path and this will link the file-upload content with the local file named $path. Creates a hard-link if the spoolfile's (see upload_tempname) temporary directory is on the same device as $path; otherwise this writes a copy.

This is useful to avoid recreating the data. This works on *nix-like systems

    my $up = $req->param( 'file_upload' );
    $up->link( '/to/my/location.png' ) ||
        die( sprintf( "Cannot symlink from %s: $!\n", $up->tempname ) );

=head2 make

Fast XS param constructor.

    my $param = Apache2::API::Request::Param::Upload->make( $pool, $name, $value );



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