File Coverage

lib/Kwiki/Archive.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Kwiki::Archive;
2 1     1   2730 use Kwiki::Plugin -Base;
  0            
  0            
3              
4             const class_id => 'archive';
5             const class_title => 'Page Archive';
6             const show_revisions => 1;
7              
8             sub register {
9             my $registry = shift;
10             $registry->add(hook => 'page:store', post => 'commit_hook');
11             }
12              
13             sub init {
14             if ($self->empty) {
15             $self->generate;
16             $self->commit_all;
17             };
18             }
19              
20             sub empty {
21             my $dir = io($self->plugin_directory);
22             $dir->exists and $dir->empty;
23             }
24              
25             sub generate {
26             my $dir = $self->plugin_directory;
27             umask 0000;
28             chmod 0777, $dir;
29             }
30              
31             sub commit_hook {
32             my $hook = pop;
33             return unless $hook->returned_true;
34             my $page = $self;
35             $self = $page->hub->archive;
36             $self->commit($page);
37             }
38              
39             sub commit_all {
40             for my $page ($self->pages->all) {
41             $self->commit($page);
42             }
43             }
44              
45             sub page_properties {
46             my $page = shift;
47             my $properties = $page->metadata->to_hash;
48             $properties->{edit_by} ||= '';
49             $properties->{edit_time} ||= scalar(gmtime);
50             $properties->{edit_unixtime} ||= scalar(time);
51             return $properties;
52             }
53              
54             sub revision_number {
55             $self->history(shift)->[0]->{revision_id} || 0;
56             }
57              
58             sub revision_numbers {
59             my $page = shift;
60             [map $_->{revision_id}, @{$self->history($page)}];
61             }
62              
63             __DATA__