Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add skeleton of models

  • Loading branch information...
commit 7df2db8c3baf30659b953854e910209b22ff9e32 1 parent b4884d4
shelling authored
1  Makefile.PL
View
@@ -12,6 +12,7 @@ requires 'Modern::Perl';
requires 'Moose';
requires 'MooseX::Getopt';
requires 'MooseX::Singleton';
+requires 'MooseX::Storage';
requires 'Namespace::Dispatch' => '0.05';
test_requires 'Test::More';
37 lib/HTTP/Balancer/Model.pm
View
@@ -0,0 +1,37 @@
+package HTTP::Balancer::Model;
+use Modern::Perl;
+use Moose;
+use File::Spec;
+
+our $dbpath = "/tmp/";
+
+sub model_name {
+ my ($self, ) = @_;
+ my $ref = ref($self);
+ $ref =~ s{HTTP::Balancer::Model::}{};
+ return lc($ref);
+}
+
+sub path {
+ my ($self, ) = @_;
+ File::Spec->catfile(
+ $dbpath,
+ $self->model_name,
+ $self->id
+ );
+}
+
+sub save {
+ my ($self, ) = @_;
+
+ my @glob = glob($self->path . "*");
+ my ($vol, $dir, $num) = File::Spec->splitpath(
+ [@glob]->[-1]
+ ) if scalar @glob;
+ $num //= 0;
+
+ $self->id($num+1) unless $self->id;
+ $self->store($self->path);
+}
+
+1;
27 lib/HTTP/Balancer/Model/Backend.pm
View
@@ -0,0 +1,27 @@
+package HTTP::Balancer::Model::Backend;
+use Modern::Perl;
+use Moose;
+use MooseX::Storage;
+extends qw( HTTP::Balancer::Model );
+
+with Storage(
+ format => 'YAML',
+ io => 'File',
+);
+
+has id => (
+ is => "rw",
+ isa => "Num",
+);
+
+has address => (
+ is => "rw",
+ isa => "Str",
+);
+
+has host_id => (
+ is => "rw",
+ isa => "Str",
+);
+
+1;
22 lib/HTTP/Balancer/Model/Host.pm
View
@@ -0,0 +1,22 @@
+package HTTP::Balancer::Model::Host;
+use Modern::Perl;
+use Moose;
+use MooseX::Storage;
+extends qw( HTTP::Balancer::Model );
+
+with Storage(
+ format => 'YAML',
+ io => 'File',
+);
+
+has id => (
+ is => "rw",
+ isa => "Num",
+);
+
+has name => (
+ is => "rw",
+ isa => "Str",
+);
+
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.