package HNS::PIM::Todo; # $Id: Todo.pm,v 1.8 1999/12/19 13:33:12 kenji Exp $ ################################################################ =head1 NAME HNS::PIM::Todo - Todo 管理クラス =head1 SYNOPSIS my $todo = new HNS::PIM::Todo(filename=>'diary/todo'); $todo->Read; print $todo->AsHTML; =cut ################################################################ use strict; use ObjectTemplate; use CodeConv; @HNS::PIM::Todo::ISA = qw(ObjectTemplate); use HNS::System; use HNS::Template; attributes qw(contents); use vars qw($MaxNum $ContentTemplate $BeginTemplate $EndTemplate); $MaxNum = 8; # template $ContentTemplate = "
  • %priority %content
  • \n"; $BeginTemplate = ""; sub initialize($) { my $self = shift; $self->contents([]); } ################################################################ =head2 $t->Read; データファイルを読み込む =cut sub Read ($) { my $self = shift; my $filename = "$HNS::System::DiaryDir/todo"; open(F, $filename) || return; while (){ next if /^$/; CodeConv::toeuc(*_); /^(\d+)\s(.*)$/; push(@{$self->contents}, {priority=>sprintf("%02d",$1), content=>$2}); } close F; } =head2 $t->AsHTML; HTML変換して返す =cut sub AsHTML ($) { my $self = shift; my $templ = new HNS::Template; my $html .= $BeginTemplate; my $cnt; for (sort {$b->{priority} <=> $a->{priority}} @{$self->contents}){ last if ++$cnt > $MaxNum; $html .= $templ->Expand($ContentTemplate, {priority=>$_->{priority}, content=>$_->{content}}); } $html .= $EndTemplate; } 1;