From fa338dd363f21135dcc77287f23a0aaa4e74159a Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 27 Mar 2011 14:48:54 +0100 Subject: bookmarks! and output as a tree --- bin/client | 9 +++- lib/DeWeave/BO/Bookmark/Base.pm | 26 +++++++++++ lib/DeWeave/BO/Bookmark/Bookmark.pm | 44 +++++++++++++++++++ lib/DeWeave/BO/Bookmark/Folder.pm | 20 +++++++++ lib/DeWeave/BO/Bookmark/Livemark.pm | 20 +++++++++ lib/DeWeave/BO/Bookmark/Microsummary.pm | 20 +++++++++ lib/DeWeave/BO/Bookmark/Query.pm | 20 +++++++++ lib/DeWeave/BO/Bookmark/Separator.pm | 14 ++++++ lib/DeWeave/Collection/Bookmarks.pm | 76 +++++++++++++++++++++++++++++++++ 9 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 lib/DeWeave/BO/Bookmark/Base.pm create mode 100644 lib/DeWeave/BO/Bookmark/Bookmark.pm create mode 100644 lib/DeWeave/BO/Bookmark/Folder.pm create mode 100644 lib/DeWeave/BO/Bookmark/Livemark.pm create mode 100644 lib/DeWeave/BO/Bookmark/Microsummary.pm create mode 100644 lib/DeWeave/BO/Bookmark/Query.pm create mode 100644 lib/DeWeave/BO/Bookmark/Separator.pm create mode 100644 lib/DeWeave/Collection/Bookmarks.pm diff --git a/bin/client b/bin/client index b09b38d..da41f14 100644 --- a/bin/client +++ b/bin/client @@ -52,5 +52,10 @@ Class::MOP::load_class($class); my $foo = $class->fetch($storage,$crypto); -print $_->as_string,"\n" for @{$foo->items}; - +if ($what eq 'Bookmarks') { + print $foo->as_tree('toolbar'); + print $foo->as_tree('menu'); +} +else { + print $_->as_string,"\n" for @{$foo->items}; +} diff --git a/lib/DeWeave/BO/Bookmark/Base.pm b/lib/DeWeave/BO/Bookmark/Base.pm new file mode 100644 index 0000000..98ebfc1 --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Base.pm @@ -0,0 +1,26 @@ +package DeWeave::BO::Bookmark::Base; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::EDO'; + +has type => ( + isa => Str, + required => 1, + is => 'ro', +); + +has parentid => ( + isa => Str, + required => 0, + is => 'ro', +); + +has parentName => ( + isa => Str, + required => 0, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Bookmark.pm b/lib/DeWeave/BO/Bookmark/Bookmark.pm new file mode 100644 index 0000000..7b235b3 --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Bookmark.pm @@ -0,0 +1,44 @@ +package DeWeave::BO::Bookmark::Bookmark; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str ArrayRef Bool); + +extends 'DeWeave::BO::Bookmark::Base'; + +has title => ( + isa => Str, + required => 1, + is => 'ro', +); + +has bmkUri => ( + isa => Str, + required => 1, + is => 'ro', +); + +has description => ( + isa => Str, + required => 0, + is => 'ro', +); + +has loadInSidebar => ( + isa => Bool, + required => 1, + is => 'ro', +); + +has tags => ( + isa => ArrayRef[Str], + required => 0, + is => 'ro', +); + +has keyword => ( + isa => Str, + required => 0, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Folder.pm b/lib/DeWeave/BO/Bookmark/Folder.pm new file mode 100644 index 0000000..3f77ff6 --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Folder.pm @@ -0,0 +1,20 @@ +package DeWeave::BO::Bookmark::Folder; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str ArrayRef); + +extends 'DeWeave::BO::Bookmark::Base'; + +has title => ( + isa => Str, + required => 1, + is => 'ro', +); + +has children => ( + isa => ArrayRef[Str], + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Livemark.pm b/lib/DeWeave/BO/Bookmark/Livemark.pm new file mode 100644 index 0000000..5737763 --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Livemark.pm @@ -0,0 +1,20 @@ +package DeWeave::BO::Bookmark::Livemark; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::BO::Bookmark::Folder'; + +has siteUri => ( + isa => Str, + required => 1, + is => 'ro', +); + +has feedUri => ( + isa => Str, + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Microsummary.pm b/lib/DeWeave/BO/Bookmark/Microsummary.pm new file mode 100644 index 0000000..51220ac --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Microsummary.pm @@ -0,0 +1,20 @@ +package DeWeave::BO::Bookmark::Microsummary; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::BO::Bookmark::Bookmark'; + +has generatorUri => ( + isa => Str, + required => 1, + is => 'ro', +); + +has staticTitle => ( + isa => Str, + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Query.pm b/lib/DeWeave/BO/Bookmark/Query.pm new file mode 100644 index 0000000..356384c --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Query.pm @@ -0,0 +1,20 @@ +package DeWeave::BO::Bookmark::Query; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::BO::Bookmark::Bookmark'; + +has folderName => ( + isa => Str, + required => 1, + is => 'ro', +); + +has queryId => ( + isa => Str, + required => 0, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/BO/Bookmark/Separator.pm b/lib/DeWeave/BO/Bookmark/Separator.pm new file mode 100644 index 0000000..860be61 --- /dev/null +++ b/lib/DeWeave/BO/Bookmark/Separator.pm @@ -0,0 +1,14 @@ +package DeWeave::BO::Bookmark::Separator; +use Moose; +use namespace::autoclean; +use MooseX::Types::Moose qw(Str); + +extends 'DeWeave::BO::Bookmark::Base'; + +has pos => ( + isa => Str, + required => 1, + is => 'ro', +); + +1; diff --git a/lib/DeWeave/Collection/Bookmarks.pm b/lib/DeWeave/Collection/Bookmarks.pm new file mode 100644 index 0000000..af1cc3e --- /dev/null +++ b/lib/DeWeave/Collection/Bookmarks.pm @@ -0,0 +1,76 @@ +package DeWeave::Collection::Bookmarks; +use Moose; +use namespace::autoclean; +use DeWeave::BO::Bookmark::Base; +use DeWeave::BO::Bookmark::Bookmark; +use DeWeave::BO::Bookmark::Microsummary; +use DeWeave::BO::Bookmark::Folder; +use DeWeave::BO::Bookmark::Livemark; +use DeWeave::BO::Bookmark::Separator; +use DeWeave::BO::Bookmark::Query; +use MooseX::Types::Moose qw(HashRef); + +extends 'DeWeave::Collection'; + +has _item_cache => ( + isa => HashRef['DeWeave::BO::Bookmark::Base'], + lazy_build => 1, + traits => ['Hash'], + handles => { + item_by_id => 'get', + item_known => 'exists', + }, +); + +sub _build__item_cache { + my ($self) = @_; + + my %ret; + + for my $item (@{$self->items}) { + $ret{$item->id}=$item; + } + + return \%ret; +} + +sub item_class { + my ($class,$input_item) = @_; + + my $item_class = 'Base'; + if (exists $input_item->{type} && defined $input_item->{type}) { + $item_class = ucfirst($input_item->{type}); + } + + return "DeWeave::BO::Bookmark::$item_class"; +} + +sub as_tree { + my ($self,$start_id) = @_; + + $start_id ||= 'menu'; + return $self->_as_tree_rec($start_id,0); +} + +sub _as_tree_rec { + my ($self,$start_id,$depth) = @_; + + if (!$self->item_known($start_id)) { + return ((' ' x $depth)." $start_id is unknown\n"); + } + + my $item = $self->item_by_id($start_id); + + my $padding = ' ' x $depth; + my $out = $item->as_string; + $out =~ s/^/$padding/smg; + + if ($item->can('children')) { + for my $child_id (@{$item->children}) { + $out .= $self->_as_tree_rec($child_id,$depth+1); + } + } + return $out; +} + +1; -- cgit v1.2.3