Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Created Oddmuse::Storage::Delegate and use it
  • Loading branch information
kensanata committed Nov 11, 2018
1 parent 3ef24c4 commit 53806ae
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions META6.json
Expand Up @@ -47,6 +47,7 @@
"Oddmuse::Save": "lib/Oddmuse/Save.pm6",
"Oddmuse::Secret": "lib/Oddmuse/Secret.pm6",
"Oddmuse::Storage": "lib/Oddmuse/Storage.pm6",
"Oddmuse::Storage::Delegate": "lib/Oddmuse/Storage/Delegate.pm6",
"Oddmuse::Storage::File": "lib/Oddmuse/Storage/File.pm6",
"Oddmuse::Storage::File::Lock": "lib/Oddmuse/Storage/File/Lock.pm6",
"Oddmuse::View": "lib/Oddmuse/View.pm6"
Expand Down
4 changes: 3 additions & 1 deletion lib/Oddmuse/Storage.pm6
Expand Up @@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

use Oddmuse::Storage::Delegate;

=begin pod
=head1 Oddmuse::Storage
Expand Down Expand Up @@ -70,7 +72,7 @@ C<templates> subdirectory with the <sp6> extension.
class Oddmuse::Storage {
my $class = %*ENV<ODDMUSE_STORAGE> || 'Oddmuse::Storage::File';
require ::($class);
has $!delegate handles <
has Oddmuse::Storage::Delegate $!delegate handles <
get-page put-page get-keep-page put-keep-page
put-change get-changes get-current-revision
lock-page unlock-page is-locked
Expand Down
82 changes: 82 additions & 0 deletions lib/Oddmuse/Storage/Delegate.pm6
@@ -0,0 +1,82 @@
# Oddmuse is a wiki engine
# Copyright (C) 2018 Alex Schroeder <alex@gnu.org>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

use Oddmuse::Page;
use Oddmuse::Change;
use Oddmuse::Filter;

=begin pod
=head1 Oddmuse::Storage::Delegate
Any module implementing the L<Oddmuse::Storage> layer must "do" this
role.
=end pod

#| Storage layer role
role Oddmuse::Storage::Delegate {

#| Return a new Page.
multi method get-page(Str $id!, Bool $is-admin --> Oddmuse::Page) is export {
return Oddmuse::Page.new();
}

#| Return a new Page, assume no admin permissions
multi method get-page(Str $id! --> Oddmuse::Page) {
return Oddmuse::Page.new();
}

#| Save a Page.
method put-page(Oddmuse::Page $page! --> Nil) is export {
}

#| Get an old revision, or the current page if it doesn't exist.
method get-keep-page(Str $id!, Int $n! --> Oddmuse::Page) is export {
return Oddmuse::Page.new();
}

#| Save new revision of a page and return the revision number.
method put-keep-page(Str $id! --> Int) is export {
return 0;
}

#| Add a Change to the log.
method put-change(Oddmuse::Change $change! --> Nil) is export {
}

#| Get the changes matching a filter from the log file.
method get-changes(Oddmuse::Filter $filter! --> List) is export {
return ();
}

#| Get the current revision for a page.
method get-current-revision(Str $id! --> Int) is export {
return 0;
}

#| Lock a page.
method lock-page(Str $id! --> Nil) is export {
}

#| Unlock a page.
method unlock-page(Str $id! --> Nil) is export {
}

#| Is this page locked?
method is-locked(Str $id! --> Bool) is export {
}
}
3 changes: 2 additions & 1 deletion lib/Oddmuse/Storage/File.pm6
Expand Up @@ -17,6 +17,7 @@
use Oddmuse::Page;
use Oddmuse::Change;
use Oddmuse::Filter;
use Oddmuse::Storage::Delegate;
use Oddmuse::Storage::File::Lock;

=begin pod
Expand All @@ -43,7 +44,7 @@ C<Oddmuse::Storage::File::Lock>.
=end pod

#| Implement storage layer using files.
class Oddmuse::Storage::File {
class Oddmuse::Storage::File does Oddmuse::Storage::Delegate {

my $SEP = "\x1e"; # ASCII UNIT SEPARATOR

Expand Down

0 comments on commit 53806ae

Please sign in to comment.