Mariachi
view release on metacpan or search on metacpan
lib/Mariachi.pm view on Meta::CPAN
);
}
=head2 ->generate_thread
=cut
sub generate_thread {
my $self = shift;
$self->generate_pages(
'index.tt2', 'index.html',
content => $self->rootset,
perpage => 20,
);
}
=head2 ->generate_date
=cut
sub generate_date {
my $self = shift;
my %touched_dates;
my %dates;
# wander things to find dirty threads, and dates
for my $root (@{ $self->rootset }) {
my $sub;
$sub = sub {
my $c = shift or return;
if (my $mail = $c->message) {
# mark the thread dirty, if the message is new
unless (-e $self->config->output."/".$mail->filename &&
!$self->config->refresh) {
# dirty up the date indexes
$touched_dates{ $mail->year } = 1;
$touched_dates{ $mail->month } = 1;
$touched_dates{ $mail->day } = 1;
}
# add things to the date indexes
push @{ $dates{ $mail->year } }, $mail;
push @{ $dates{ $mail->month } }, $mail;
push @{ $dates{ $mail->day } }, $mail;
}
};
$root->iterate_down($sub);
undef $sub; # since we closed over ourself, we'll have to be specific
}
for ( keys %touched_dates ) {
my @mails = sort {
$a->epoch_date <=> $b->epoch_date
} @{ $dates{$_} };
my @depth = split m!/!;
$self->generate_pages( 'date.tt2', "$_/index.html",
archive_date => $_,
content => \@mails,
base => "../" x @depth,
perpage => 20,
);
}
}
=head2 ->generate_bodies
render thread tree into the directory of C<output>
=cut
sub generate_bodies {
my $self = shift;
my %touched_threads;
# wander things to find dirty threads
for my $root (@{ $self->rootset }) {
my $sub;
$sub = sub {
if (my $mail = eval { $_[0]->message }) {
# mark the thread dirty, if the message is new
$touched_threads{ $root } = $root
unless -e $self->config->output."/".$mail->filename
&& !$self->config->refresh;
}
};
$root->iterate_down($sub);
undef $sub; # since we closed over ourself, we'll have to be specific
}
# figure out adjacent dirty threads
my @threads = @{ $self->rootset };
for my $i (grep { $touched_threads{ $threads[$_] } } 0..$#threads) {
$touched_threads{ $threads[$i-1] } = $threads[$i-1] if $i > 0;
$touched_threads{ $threads[$i+1] } = $threads[$i+1] if $i+1 < @threads;
}
# and then render all the messages in the dirty threads
my $count = 0;
my $tt = $self->tt;
for my $root (values %touched_threads) {
my $sub = sub {
my $mail = $_[0]->message or return;
print STDERR "\rmessage $count" if ++$count % 100 == 0;
$tt->process('message.tt2',
{ base => '../../../',
mariachi => $self,
thread => $root,
message => $mail,
container => $_[0],
},
$self->config->output . "/" . $mail->filename)
or die $tt->error;
};
$root->recurse_down( $sub );
( run in 0.809 second using v1.01-cache-2.11-cpan-71847e10f99 )