Business-Monzo

 view release on metacpan or  search on metacpan

lib/Business/Monzo/Resource.pm  view on Meta::CPAN

package Business::Monzo::Resource;

=head1 NAME

Business::Monzo::Resource

=head1 DESCRIPTION

This is a base class for Monzo resource classes, it implements common
behaviour. You shouldn't use this class directly, but extend it instead.

=cut

use strict;
use warnings;

use Moo;
use Carp qw/ confess carp /;
use Mojo::JSON qw/ encode_json /;
use Scalar::Util qw/ blessed /;
use Try::Tiny;

=head1 ATTRIBUTES

The Resource class has the following attributes (with their type).

    client (Business::Monzo::Client) - REQUIRED
    url (Str)
    url_no_id (Str)

=cut

has client => (
    is       => 'ro',
    isa      => sub {
        confess( "$_[0] is not a Business::Monzo::Client" )
            if ref $_[0] ne 'Business::Monzo::Client';

        $Business::Monzo::Resource::client = $_[0];
    },
    required => 1,
);

has [ qw/ url / ] => (
    is      => 'ro',
    lazy    => 1,
    default => sub {
        my ( $self ) = @_;
        join( '/',$self->url_no_id,$self->id )
    },
);

has [ qw/ url_no_id / ] => (
    is      => 'ro',
    lazy    => 1,
    default => sub {
        my ( $self ) = @_;
        return join(
            '/',
            $self->client->api_url,
            lc( ( split( ':',ref( $self ) ) )[-1] ) . 's',
        );
    },
);

=head1 METHODS

=head2 to_hash

Returns a hash representation of the object.

    my %data = $transaction->to_hash;

=cut

sub to_hash {
    my ( $self ) = @_;

    my %hash = %{ $self };

    delete( $hash{client} );



( run in 1.570 second using v1.01-cache-2.11-cpan-5a3173703d6 )