HTTP-Balancer

 view release on metacpan or  search on metacpan

lib/HTTP/Balancer/Model.pm  view on Meta::CPAN

package HTTP::Balancer::Model;
use Modern::Perl;
use Moose;
use File::Spec;
use Path::Tiny qw(!path);

with qw(HTTP::Balancer::Role);

=head1 NAME

HTTP::Balancer::Model - the base class of models of HTTP::Balancer

=head1 SYNOPSIS

    package HTTP::Balancer::Model::Foo;
    use Modern::Perl;

    use Moose;
    extends qw(HTTP::Balancer::Model);

    use MoooseX::Storage;
    with Storage(format => 'YAML', io => 'File');

=head1 FUNCTIONS AND METHODS

=head2 models

returns the list of last name of HTTP::Balancer::Model::*

=cut

sub models {
    my $class = ref($_[0]) ? ref(shift) : shift;
    require Namespace::Dispatch;
    map { $class->model($_) }
    @{Namespace::Dispatch::leaves($class)};
}

=head2 model_name

class method and instance method

returns lowercase of last name of current model

=cut

sub model_name {
    my ($self, ) = @_;
    my $ref = ref($self) || $self;
    $ref =~ s{HTTP::Balancer::Model::}{};
    return lc($ref);
}

=head2 model_dir

class method and instance method

returns the directory store the entities of current model

=cut

sub model_dir {
    my ($self, ) = @_;
    File::Spec->catdir(
        $self->config->dbpath,
        $self->model_name
    );
}

=head2 path

instance method

returns the path for storing current object

=cut



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