summaryrefslogtreecommitdiff
path: root/lib/DeWeave
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2011-03-26 12:40:12 +0000
committerdakkar <dakkar@thenautilus.net>2011-03-26 12:40:12 +0000
commitb398c46825dc73ac92677893dd2a714cd21f8a4d (patch)
tree6842b365f072b6fd761e5044be1093791584d6bb /lib/DeWeave
parentcrypto works! (diff)
downloadDeWeave-b398c46825dc73ac92677893dd2a714cd21f8a4d.tar.gz
DeWeave-b398c46825dc73ac92677893dd2a714cd21f8a4d.tar.bz2
DeWeave-b398c46825dc73ac92677893dd2a714cd21f8a4d.zip
collections working, subclasses, strings
Diffstat (limited to 'lib/DeWeave')
-rw-r--r--lib/DeWeave/BO/Client.pm26
-rw-r--r--lib/DeWeave/Collection.pm36
-rw-r--r--lib/DeWeave/Collection/Clients.pm8
-rw-r--r--lib/DeWeave/EDO.pm5
-rw-r--r--lib/DeWeave/WBO.pm33
5 files changed, 104 insertions, 4 deletions
diff --git a/lib/DeWeave/BO/Client.pm b/lib/DeWeave/BO/Client.pm
new file mode 100644
index 0000000..e9f9ae8
--- /dev/null
+++ b/lib/DeWeave/BO/Client.pm
@@ -0,0 +1,26 @@
+package DeWeave::BO::Client;
+use Moose;
+use namespace::autoclean;
+use MooseX::Types::Moose qw(Str ArrayRef);
+
+extends 'DeWeave::EDO';
+
+has name => (
+ isa => Str,
+ required => 1,
+ is => 'ro',
+);
+
+has type => (
+ isa => Str,
+ required => 1,
+ is => 'ro',
+);
+
+has commands => (
+ isa => ArrayRef[Str],
+ required => 0,
+ is => 'ro',
+);
+
+1;
diff --git a/lib/DeWeave/Collection.pm b/lib/DeWeave/Collection.pm
index 42669ba..92c5342 100644
--- a/lib/DeWeave/Collection.pm
+++ b/lib/DeWeave/Collection.pm
@@ -1,9 +1,10 @@
package DeWeave::Collection;
use Moose;
use namespace::autoclean;
-use MooseX::Types::Moose qw(ArrayRef Int Str Num);
+use MooseX::Types::Moose qw(ArrayRef);
use JSON::Any;
use DeWeave::EDO;
+use Lingua::EN::Inflect::Number 'to_S';
has items => (
isa => ArrayRef['DeWeave::WBO'],
@@ -11,6 +12,25 @@ has items => (
required => 1,
);
+sub _local_part {
+ my ($class) = @_;
+ my ($sub) = ($class =~ m{^DeWeave::Collection::(\w+)});
+ return $sub;
+}
+
+sub item_class {
+ my ($class) = @_;
+ my $sub = ucfirst(to_S(lc($class->_local_part)));
+ return "DeWeave::BO::$sub" if $sub;
+ return 'DeWeave::WBO'
+}
+
+sub items_path {
+ my ($class) = @_;
+ my $sub = lc($class->_local_part);
+ return "storage/$sub";
+}
+
sub from_json {
my ($class,$json,$crypt)=@_;
@@ -19,11 +39,23 @@ sub from_json {
my $args = $j->decode($json);
my @items = map {
- DeWeave::EDO->new({%$_,__crypt=>$crypt})
+ $class->item_class->new({%$_,__crypt=>$crypt})
} @$args;
return $class->new({
items => \@items,
});
}
+sub fetch {
+ my ($class,$storage,$crypto) = @_;
+
+ my $path = $class->items_path;
+ my $data = $storage->get_item($path);
+
+ return $class->from_json(
+ $data,
+ $crypto,
+ );
+}
+
1;
diff --git a/lib/DeWeave/Collection/Clients.pm b/lib/DeWeave/Collection/Clients.pm
new file mode 100644
index 0000000..a49e54a
--- /dev/null
+++ b/lib/DeWeave/Collection/Clients.pm
@@ -0,0 +1,8 @@
+package DeWeave::Collection::Clients;
+use Moose;
+use namespace::autoclean;
+use DeWeave::BO::Client;
+
+extends 'DeWeave::Collection';
+
+1;
diff --git a/lib/DeWeave/EDO.pm b/lib/DeWeave/EDO.pm
index f7a605f..3c32c84 100644
--- a/lib/DeWeave/EDO.pm
+++ b/lib/DeWeave/EDO.pm
@@ -4,23 +4,25 @@ use namespace::autoclean;
use MooseX::Types::Moose qw(Int Str Num);
use JSON::Any;
use Try::Tiny;
-use Data::Dump 'pp';
extends 'DeWeave::WBO';
has ciphertext => (
+ traits => ['WBOInternal'],
isa => Str,
required => 1,
is => 'ro',
);
has IV => (
+ traits => ['WBOInternal'],
isa => Str,
required => 1,
is => 'ro',
);
has hmac => (
+ traits => ['WBOInternal'],
isa => Str,
required => 1,
is => 'ro',
@@ -43,6 +45,7 @@ around BUILDARGS => sub {
@$args{keys %$extra_args} =
values %$extra_args;
}
+
return $args;
};
diff --git a/lib/DeWeave/WBO.pm b/lib/DeWeave/WBO.pm
index 8d8a1ba..56bc3e1 100644
--- a/lib/DeWeave/WBO.pm
+++ b/lib/DeWeave/WBO.pm
@@ -1,9 +1,10 @@
-package DeWeave::WBO;
+package DeWeave::WBO;{
use Moose;
use namespace::autoclean;
use MooseX::Types::Moose qw(Int Str Num);
use JSON::Any;
use Try::Tiny;
+use Data::Dump 'pp';
has id => (
isa => Str,
@@ -24,6 +25,7 @@ has sortindex => (
);
has payload => (
+ traits => ['WBOInternal'],
isa => Str,
required => 1,
is => 'ro',
@@ -66,5 +68,34 @@ around BUILDARGS => sub {
return $args;
};
+sub as_string {
+ my ($self) = @_;
+
+ my $meta = $self->meta;
+
+ my $str = '';
+
+ for my $attribute ( $meta->get_all_attributes ) {
+
+ next if $attribute->does('DeWeave::WBO::Meta::Attribute::Internal');
+ next unless $attribute->has_value($self);
+
+ my $reader = $attribute->get_read_method;
+ $str .= sprintf "%s -> %s\n",
+ $attribute->name,
+ pp ($self->$reader);
+ }
+
+ return $str;
+}
+}
+
+package DeWeave::WBO::Meta::Attribute::Internal;{
+use Moose::Role;
+}
+
+package Moose::Meta::Attribute::Custom::Trait::WBOInternal;{
+sub register_implementation { 'DeWeave::WBO::Meta::Attribute::Internal' }
+}
1;