API-MailboxOrg
view release on metacpan or search on metacpan
lib/API/MailboxOrg.pm view on Meta::CPAN
package API::MailboxOrg;
use v5.24;
# ABSTRACT: Perl library to work with the API for the Mailbox.org API
use strict;
use warnings;
use Carp;
use Moo;
use Mojo::File;
use Mojo::Loader qw(find_modules load_class);
use Mojo::UserAgent;
use Mojo::Util qw(decamelize);
use Scalar::Util qw(weaken);
use Types::Mojo qw(:all);
use Types::Standard qw(Str);
use feature 'signatures';
no warnings 'experimental::signatures';
our $VERSION = '1.0.2'; # VERSION
has user => ( is => 'ro', isa => Str, required => 1 );
has password => ( is => 'ro', isa => Str, required => 1 );
has token => ( is => 'rwp', isa => Str );
has host => ( is => 'ro', isa => MojoURL["https?"], default => sub { 'https://api.mailbox.org' }, coerce => 1 );
has base_uri => ( is => 'ro', isa => Str, default => sub { 'v1/' } );
has client => (
is => 'ro',
lazy => 1,
isa => MojoUserAgent,
default => sub {
Mojo::UserAgent->new
}
);
sub _load_namespace ($package) {
my @modules = find_modules $package . '::API', { recursive => 1 };
for my $module ( @modules ) {
load_class( $module );
my $base = (split /::/, $module)[-1];
no strict 'refs'; ## no critic
*{ $package . '::' . decamelize( $base ) } = sub ($api) {
weaken $api;
state $object //= $module->instance(
api => $api,
);
return $object;
};
}
}
__PACKAGE__->_load_namespace;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
API::MailboxOrg - Perl library to work with the API for the Mailbox.org API
=head1 VERSION
version 1.0.2
=head1 SYNOPSIS
use API::MailboxOrg;
( run in 1.165 second using v1.01-cache-2.11-cpan-39bf76dae61 )