From 63ea2492d1b7676d5aae7c9dd7912ca78159c321 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 26 Mar 2011 13:44:35 +0000 Subject: many more BrowserObjects --- bin/client | 7 ++++++ lib/DeWeave/BO/Form.pm | 20 +++++++++++++++ lib/DeWeave/BO/History.pm | 49 ++++++++++++++++++++++++++++++++++++ lib/DeWeave/BO/Password.pm | 50 +++++++++++++++++++++++++++++++++++++ lib/DeWeave/BO/Pref.pm | 14 +++++++++++ lib/DeWeave/BO/Tab.pm | 26 +++++++++++++++++++ lib/DeWeave/Collection.pm | 22 +++++++++++++--- lib/DeWeave/Collection/Forms.pm | 8 ++++++ lib/DeWeave/Collection/History.pm | 8 ++++++ lib/DeWeave/Collection/Passwords.pm | 8 ++++++ lib/DeWeave/Collection/Prefs.pm | 8 ++++++ lib/DeWeave/Collection/Tabs.pm | 8 ++++++ lib/DeWeave/EDO.pm | 18 ++++++++++++- lib/DeWeave/Exception/Deleted.pm | 9 +++++++ lib/DeWeave/WBO.pm | 21 ++++++++++++++++ 15 files changed, 272 insertions(+), 4 deletions(-) create mode 100644 lib/DeWeave/BO/Form.pm create mode 100644 lib/DeWeave/BO/History.pm create mode 100644 lib/DeWeave/BO/Password.pm create mode 100644 lib/DeWeave/BO/Pref.pm create mode 100644 lib/DeWeave/BO/Tab.pm create mode 100644 lib/DeWeave/Collection/Forms.pm create mode 100644 lib/DeWeave/Collection/History.pm create mode 100644 lib/DeWeave/Collection/Passwords.pm create mode 100644 lib/DeWeave/Collection/Prefs.pm create mode 100644 lib/DeWeave/Collection/Tabs.pm create mode 100644 lib/DeWeave/Exception/Deleted.pm diff --git a/bin/client b/bin/client index c5e2a65..b09b38d 100644 --- a/bin/client +++ b/bin/client @@ -7,6 +7,13 @@ use DeWeave::Crypto; use DeWeave::Collection; use Getopt::Long; use Class::MOP; +use Log::Log4perl; + +Log::Log4perl->easy_init({ + level => 'WARN', + utf8 => 1, + layout => '%c %M %m', +}); my ($server,$username,$password,$sync_key,$what); diff --git a/lib/DeWeave/BO/Form.pm b/lib/DeWeave/BO/Form.pm new file mode 100644 index 0000000..e1762fb --- /dev/null +++ b/lib/DeWeave/BO/Form.pm @@ -0,0 +1,20 @@ +package DeWeave::BO::Form; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::EDO'; + +has name => ( + isa => Str, + required => 1, + is => 'ro', +); + +has value => ( + isa => Str, + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/History.pm b/lib/DeWeave/BO/History.pm new file mode 100644 index 0000000..3e9040e --- /dev/null +++ b/lib/DeWeave/BO/History.pm @@ -0,0 +1,49 @@ +package DeWeave::BO::History; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str ArrayRef Int); +use MooseX::Types::Structured qw(Dict); + +extends 'DeWeave::EDO'; + +has histUri => ( + isa => Str, + required => 1, + is => 'ro', +); + +has title => ( + isa => Str, + required => 0, + is => 'ro', +); + +has visits => ( + isa => ArrayRef[Dict[date => Int, type => Int]], + required => 1, + is => 'ro', +); + +{ +my @visit_types=( + undef, + 'link', + 'typed', + 'bookmark', + 'embed', + 'redirect_permanent', + 'redirect_temporary', + 'download', + 'framed_link', +); +sub visit_type { + my ($self,$type_int) = @_; + + if ($type_int > 0 && $type_int < @visit_types) { + return $visit_types[$type_int]; + } + return undef; +} +} + +1; diff --git a/lib/DeWeave/BO/Password.pm b/lib/DeWeave/BO/Password.pm new file mode 100644 index 0000000..6839d66 --- /dev/null +++ b/lib/DeWeave/BO/Password.pm @@ -0,0 +1,50 @@ +package DeWeave::BO::Password; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::EDO'; + +has hostname => ( + isa => Str, + required => 1, + is => 'ro', +); + +has formSubmitURL => ( + isa => Str, + required => 0, + is => 'ro', +); + +has httpRealm => ( + isa => Str, + required => 0, + is => 'ro', +); + +has username => ( + isa => Str, + required => 1, + is => 'ro', +); + +has password => ( + isa => Str, + required => 1, + is => 'ro', +); + +has usernameField => ( + isa => Str, + required => 0, + is => 'ro', +); + +has passwordField => ( + isa => Str, + required => 0, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Pref.pm b/lib/DeWeave/BO/Pref.pm new file mode 100644 index 0000000..5372da2 --- /dev/null +++ b/lib/DeWeave/BO/Pref.pm @@ -0,0 +1,14 @@ +package DeWeave::BO::Pref; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(HashRef); + +extends 'DeWeave::EDO'; + +has value => ( + isa => HashRef, + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Tab.pm b/lib/DeWeave/BO/Tab.pm new file mode 100644 index 0000000..94f46b0 --- /dev/null +++ b/lib/DeWeave/BO/Tab.pm @@ -0,0 +1,26 @@ +package DeWeave::BO::Tab; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(ArrayRef Str Int Undef); +use MooseX::Types::Structured qw(Dict Optional); + +extends 'DeWeave::EDO'; + +has clientName => ( + isa => Str, + required => 1, + is => 'ro', +); + +has tabs => ( + isa => ArrayRef[Dict[ + title => Undef|Str, + urlHistory => ArrayRef[Str], + icon => Undef|Str, + lastUsed => Int, + ]], + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/Collection.pm b/lib/DeWeave/Collection.pm index 92c5342..6ad87eb 100644 --- a/lib/DeWeave/Collection.pm +++ b/lib/DeWeave/Collection.pm @@ -3,8 +3,11 @@ use Moose; use namespace::autoclean; use MooseX::Types::Moose qw(ArrayRef); use JSON::Any; +use Try::Tiny; use DeWeave::EDO; use Lingua::EN::Inflect::Number 'to_S'; +use Log::Log4perl ':easy'; +use Data::Dump 'pp'; has items => ( isa => ArrayRef['DeWeave::WBO'], @@ -38,9 +41,22 @@ sub from_json { my $args = $j->decode($json); - my @items = map { - $class->item_class->new({%$_,__crypt=>$crypt}) - } @$args; +DEBUG '$args ',{filter=>\&pp,value=>$args}; + + my @items; + + for my $input_item (@$args) { + my $item; + try { + $item = $class->item_class->new({%$input_item,__crypt=>$crypt}) + } + catch { + die $_ unless ref($_) && $_->isa('DeWeave::Exception::Deleted'); + }; + push @items,$item + if $item; + } + return $class->new({ items => \@items, }); diff --git a/lib/DeWeave/Collection/Forms.pm b/lib/DeWeave/Collection/Forms.pm new file mode 100644 index 0000000..9168085 --- /dev/null +++ b/lib/DeWeave/Collection/Forms.pm @@ -0,0 +1,8 @@ +package DeWeave::Collection::Forms; +use Moose; +use namespace::autoclean; +use DeWeave::BO::Form; + +extends 'DeWeave::Collection'; + +1; diff --git a/lib/DeWeave/Collection/History.pm b/lib/DeWeave/Collection/History.pm new file mode 100644 index 0000000..4bd4814 --- /dev/null +++ b/lib/DeWeave/Collection/History.pm @@ -0,0 +1,8 @@ +package DeWeave::Collection::History; +use Moose; +use namespace::autoclean; +use DeWeave::BO::History; + +extends 'DeWeave::Collection'; + +1; diff --git a/lib/DeWeave/Collection/Passwords.pm b/lib/DeWeave/Collection/Passwords.pm new file mode 100644 index 0000000..6361dbd --- /dev/null +++ b/lib/DeWeave/Collection/Passwords.pm @@ -0,0 +1,8 @@ +package DeWeave::Collection::Passwords; +use Moose; +use namespace::autoclean; +use DeWeave::BO::Password; + +extends 'DeWeave::Collection'; + +1; diff --git a/lib/DeWeave/Collection/Prefs.pm b/lib/DeWeave/Collection/Prefs.pm new file mode 100644 index 0000000..3b5d3e5 --- /dev/null +++ b/lib/DeWeave/Collection/Prefs.pm @@ -0,0 +1,8 @@ +package DeWeave::Collection::Prefs; +use Moose; +use namespace::autoclean; +use DeWeave::BO::Pref; + +extends 'DeWeave::Collection'; + +1; diff --git a/lib/DeWeave/Collection/Tabs.pm b/lib/DeWeave/Collection/Tabs.pm new file mode 100644 index 0000000..fe6b5b9 --- /dev/null +++ b/lib/DeWeave/Collection/Tabs.pm @@ -0,0 +1,8 @@ +package DeWeave::Collection::Tabs; +use Moose; +use namespace::autoclean; +use DeWeave::BO::Tab; + +extends 'DeWeave::Collection'; + +1; diff --git a/lib/DeWeave/EDO.pm b/lib/DeWeave/EDO.pm index 3c32c84..81250d2 100644 --- a/lib/DeWeave/EDO.pm +++ b/lib/DeWeave/EDO.pm @@ -1,9 +1,10 @@ package DeWeave::EDO; use Moose; use namespace::autoclean; -use MooseX::Types::Moose qw(Int Str Num); +use MooseX::Types::Moose qw(Int Str Num Bool); use JSON::Any; use Try::Tiny; +use DeWeave::Exception::Deleted; extends 'DeWeave::WBO'; @@ -28,6 +29,12 @@ has hmac => ( is => 'ro', ); +has deleted => ( + isa => Bool, + required => 0, + is => 'ro', +); + around BUILDARGS => sub { my $orig = shift; my $class = shift; @@ -46,6 +53,15 @@ around BUILDARGS => sub { values %$extra_args; } + delete @$args{grep {!defined $args->{$_}} keys %$args}; + + $class->_debug_data('buildargs: ',$args); + + if ($args->{deleted}) { + delete $args->{__crypt}; + die DeWeave::Exception::Deleted->new({args=>$args}); + } + return $args; }; diff --git a/lib/DeWeave/Exception/Deleted.pm b/lib/DeWeave/Exception/Deleted.pm new file mode 100644 index 0000000..7b2f508 --- /dev/null +++ b/lib/DeWeave/Exception/Deleted.pm @@ -0,0 +1,9 @@ +package DeWeave::Exception::Deleted; +use Moose; + +has args => ( + is => 'ro', + required => 0, +); + +1; diff --git a/lib/DeWeave/WBO.pm b/lib/DeWeave/WBO.pm index 56bc3e1..d38120f 100644 --- a/lib/DeWeave/WBO.pm +++ b/lib/DeWeave/WBO.pm @@ -4,6 +4,7 @@ use namespace::autoclean; use MooseX::Types::Moose qw(Int Str Num); use JSON::Any; use Try::Tiny; +use Log::Log4perl ':easy'; use Data::Dump 'pp'; has id => ( @@ -37,6 +38,20 @@ has ttl => ( is => 'ro', ); +sub _debug_data { + my ($self,$msg,$data) = @_; + + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth+1; + + my %data_clean;my @keys_clean = grep {!/^_/} keys %$data; + @data_clean{@keys_clean} = @$data{@keys_clean}; + + DEBUG $msg, { + filter => \&pp, + value => \%data_clean, + }; +} + sub from_json { my ($class,$json,$crypt)=@_; @@ -44,6 +59,8 @@ sub from_json { my $args = $j->decode($json); + $class->_debug_data('$args ',$args); + if (defined $args->{payload}) { $args->{__crypt}=$crypt; } @@ -65,6 +82,10 @@ around BUILDARGS => sub { @$args{keys %$extra_args} = values %$extra_args; + delete @$args{grep {!defined $args->{$_}} keys %$args}; + + $class->_debug_data('buildargs: ',$args); + return $args; }; -- cgit v1.2.3