line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::TimelineAggregate; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4637278
|
use meon::Web::SPc; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
32
|
|
4
|
2
|
|
|
2
|
|
793
|
use meon::Web::Util; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use meon::Web::TimelineEntry; |
6
|
|
|
|
|
|
|
use DateTime::Format::Strptime; |
7
|
|
|
|
|
|
|
use File::Copy 'copy'; |
8
|
|
|
|
|
|
|
use Path::Class qw(); |
9
|
|
|
|
|
|
|
use IO::Any; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Moose; |
12
|
|
|
|
|
|
|
use MooseX::Types::Path::Class; |
13
|
|
|
|
|
|
|
use 5.010; |
14
|
|
|
|
|
|
|
use utf8; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'timeline_dir' => (is=>'rw', isa=>'Path::Class::Dir', required => 1); |
17
|
|
|
|
|
|
|
has 'timeline_sub_dir' => (is=>'rw', isa=>'Path::Class::Dir', required => 1); |
18
|
|
|
|
|
|
|
has 'other_timeline_dirs' => (is=>'rw', isa=>'ArrayRef[Path::Class::Dir]', required => 1); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub refresh { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
my $dir = $self->timeline_sub_dir; |
23
|
|
|
|
|
|
|
my $timeline_dir = $self->timeline_dir; |
24
|
|
|
|
|
|
|
my $aggregated_file = $dir->file('index.xml'); |
25
|
|
|
|
|
|
|
my $xpc = meon::Web::Util->xpc; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$dir->mkpath |
28
|
|
|
|
|
|
|
unless -e $dir; |
29
|
|
|
|
|
|
|
unless (-e $dir->file('index.xml')) { |
30
|
|
|
|
|
|
|
$dir->resolve; |
31
|
|
|
|
|
|
|
$timeline_dir->resolve; |
32
|
|
|
|
|
|
|
my $list_index_file = Path::Class::file( |
33
|
|
|
|
|
|
|
meon::Web::SPc->datadir, 'meon-web', 'template', 'xml','timeline-list-index.xml' |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
my $timeline_index_file = Path::Class::file( |
36
|
|
|
|
|
|
|
meon::Web::SPc->datadir, 'meon-web', 'template', 'xml','timeline-index.xml' |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
copy($list_index_file, $aggregated_file) or die 'copy failed: '.$!; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
while (($dir = $dir->parent) && $timeline_dir->contains($dir) && !-e $dir->file('index.xml')) { |
41
|
|
|
|
|
|
|
copy($timeline_index_file, $dir->file('index.xml')) or die 'copy failed: '.$!; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $timeline_dom = XML::LibXML->load_xml(location => $aggregated_file); |
46
|
|
|
|
|
|
|
my ($timeline_el) = $xpc->findnodes('/w:page/w:content//w:timeline', $timeline_dom); |
47
|
|
|
|
|
|
|
die 'timeline element missing' |
48
|
|
|
|
|
|
|
unless $timeline_el; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
foreach my $old_entry ($timeline_el->childNodes()) { |
51
|
|
|
|
|
|
|
$timeline_el->removeChild($old_entry); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
$timeline_el->appendText("\n"); |
54
|
|
|
|
|
|
|
$timeline_el->setAttribute('class' => 'aggregate'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my @entries_files; |
57
|
|
|
|
|
|
|
foreach my $other_timeline_dir (@{$self->other_timeline_dirs}) { |
58
|
|
|
|
|
|
|
next unless -d $other_timeline_dir; |
59
|
|
|
|
|
|
|
push(@entries_files, $other_timeline_dir->children(no_hidden => 1)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my @entries = |
63
|
|
|
|
|
|
|
map { substr($_,0,-4) } # remove .xml |
64
|
|
|
|
|
|
|
map { $_->relative($dir) } |
65
|
|
|
|
|
|
|
grep { $_->basename ne 'index.xml' } |
66
|
|
|
|
|
|
|
grep { !$_->is_dir } |
67
|
|
|
|
|
|
|
@entries_files |
68
|
|
|
|
|
|
|
; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
foreach my $entry (@entries) { |
71
|
|
|
|
|
|
|
my $entry_node = $timeline_el->addNewChild( undef, 'w:timeline-entry' ); |
72
|
|
|
|
|
|
|
$entry_node->setAttribute('href' => $entry); |
73
|
|
|
|
|
|
|
$timeline_el->appendText("\n"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
IO::Any->spew($aggregated_file, $timeline_dom->toString, { atomic => 1 }); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |