— |
our $VERSION = '1.0' ;
sub make_document {
my ( $self , $file ) = @_ ;
return unless $file ;
open ( my ( $in ), $file ) or return ;
local $/ = "\n" ;
my $who = getpwuid (( stat $file )[4]);
$file =~ s/\.txt$//;
my $when = < $in >;
my $title = < $in >;
chomp $title ;
local $/;
my $content = < $in >;
close $in ;
my $comments = [];
$comments = [_read_comments( $file , $file . ".comments" ) ]
if -e $file . ".comments" ;
my $dir = dirname( $file );
$dir =~ s{^\./?}{};
my $category = $dir || "main" ;
return Bryar::Document->new(
title => $title ,
content => $content ,
epoch => $when ,
author => $who ,
id => $file ,
category => $category ,
comments => $comments
);
}
sub _read_comments {
my ( $id , $file ) = @_ ;
open COMMENTS, $file or die $!;
local $/;
my $stuff = <COMMENTS>;
my @rv ;
for ( split /-----\n/, $stuff ) {
push @rv ,
Bryar::Comment->new(
id => $id ,
map {/^(\w+): (.*)/; $ 1 => $2 } split /\n/, $_
)
}
return @rv ;
}
1;
|