summaryrefslogtreecommitdiff
path: root/fml
diff options
context:
space:
mode:
authorfukachan <fukachan>2006-09-24 10:24:20 +0000
committerfukachan <fukachan>2006-09-24 10:24:20 +0000
commite7dead9124e08125a24dea900012c01ff8337ecd (patch)
tree1d8f5e8be8660cf1aba2f5fdc603bf8b1ebd67ac /fml
parent2743e8ebd2395313edf5dc74a2f4b20e5564aeca (diff)
downloadfml8-e7dead9124e08125a24dea900012c01ff8337ecd.tar.gz
fml8-e7dead9124e08125a24dea900012c01ff8337ecd.tar.bz2
fml8-e7dead9124e08125a24dea900012c01ff8337ecd.zip
NL-ify (use FML::Demo::Language if needed)
enabled to expand YY/DD-YY/DD form to date list. cosmetics. status and misc support.
Diffstat (limited to 'fml')
-rw-r--r--fml/lib/FML/Demo/Language/Japanese.pm80
-rw-r--r--fml/lib/FML/Demo/Project.pm143
2 files changed, 202 insertions, 21 deletions
diff --git a/fml/lib/FML/Demo/Language/Japanese.pm b/fml/lib/FML/Demo/Language/Japanese.pm
new file mode 100644
index 00000000..df0d1c7a
--- /dev/null
+++ b/fml/lib/FML/Demo/Language/Japanese.pm
@@ -0,0 +1,80 @@
+#-*- perl -*-
+#
+# Copyright (C) 2006 Ken'ichi Fukamachi
+# All rights reserved. This program is free software; you can
+# redistribute it and/or modify it under the same terms as Perl itself.
+#
+# $FML: @template.pm,v 1.10 2006/01/07 13:16:41 fukachan Exp $
+#
+
+package FML::Demo::Language::Japanese;
+use strict;
+use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
+use Carp;
+
+=head1 NAME
+
+FML::Demo::Language::Japanese - what is this
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 METHODS
+
+=head2 new()
+
+constructor.
+
+=cut
+
+
+# Descriptions: constructor.
+# Arguments: OBJ($self)
+# Side Effects: none
+# Return Value: OBJ
+sub new
+{
+ my ($self) = @_;
+ my ($type) = ref($self) || $self;
+ my $me = {};
+ return bless $me, $type;
+}
+
+
+# Descriptions: return mark.
+# Arguments: OBJ($self)
+# Side Effects: none
+# Return Value: STR
+sub get_mark
+{
+ my ($self) = @_;
+
+ return 'ąŁ';
+}
+
+
+=head1 CODING STYLE
+
+See C<http://www.fml.org/software/FNF/> on fml coding style guide.
+
+=head1 AUTHOR
+
+Ken'ichi Fukamachi
+
+=head1 COPYRIGHT
+
+Copyright (C) 2006 Ken'ichi Fukamachi
+
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the same terms as Perl itself.
+
+=head1 HISTORY
+
+FML::Demo::Language::Japanese appeared in fml8 mailing list driver package.
+See C<http://www.fml.org/> for more details.
+
+=cut
+
+
+1;
diff --git a/fml/lib/FML/Demo/Project.pm b/fml/lib/FML/Demo/Project.pm
index a145183a..1d88ae96 100644
--- a/fml/lib/FML/Demo/Project.pm
+++ b/fml/lib/FML/Demo/Project.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: Project.pm,v 1.1 2006/02/01 12:35:45 fukachan Exp $
+# $FML: Project.pm,v 1.2 2006/07/09 12:11:12 fukachan Exp $
#
package FML::Demo::Project;
@@ -12,6 +12,9 @@ use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD);
use Carp;
+my $global_language = "Japanese";
+
+
=head1 NAME
FML::Demo::Project - generate pseudo Gantt chart (demonstration module).
@@ -54,20 +57,25 @@ sub parse
use FileHandle;
my $rh = new FileHandle $file;
if (defined $rh) {
- my ($buf, $line, $level, $date, $comment);
+ my ($buf, $line, $level, $date_list, $status, $comment);
LINE:
while ($buf = <$rh>) {
next if $buf =~ /^\#/o;
- $line++;
- $data->[ $line ] = {};
- $level = 0;
- $date = '';
- $comment = '';
+ $level = 0;
+ $date_list = [];
+ $status = '';
+ $comment = '';
- if ($buf =~ /^\%format/) { $self->_parse_format($buf); next LINE;}
- if ($buf =~ /^\%alias/) { $self->_parse_alias($buf); next LINE;}
+ if ($buf =~ /^\%format/) {
+ $self->_parse_format($buf);
+ next LINE;
+ }
+ if ($buf =~ /^\%alias/) {
+ $self->_parse_alias($buf);
+ next LINE;
+ }
if ($buf =~ /^\%date_range/) {
$self->_parse_date_range($buf);
next LINE;
@@ -77,12 +85,19 @@ sub parse
if ($buf =~ /^\t{2}\S+/) { $level = 3;}
if ($buf =~ /^\t{3}\S+/) { $level = 4;}
+ $line++;
+ $data->[ $line ] = {};
+
$buf =~ s/^\s*//;
my ($title, @_data) = split(/\s+/, $buf);
DATA:
for my $s (@_data) {
- if ($s =~ /\d+\/\d+/ || $s =~ /\d+\/\d+\/\d+/) {
- $date = $self->_canonical_date($s);
+ if ($s =~ /^[-\d+\/]+$/) {
+ $date_list = $self->_get_canonical_date_list($s);
+ next DATA;
+ }
+ elsif ($s =~ /^DONE|WAIT$/) {
+ $status = $s;
next DATA;
}
else {
@@ -90,10 +105,11 @@ sub parse
}
}
- $data->[ $line ]->{ level } = $level;
- $data->[ $line ]->{ title } = $title;
- $data->[ $line ]->{ date } = $date;
- $data->[ $line ]->{ comment } = $comment;
+ $data->[ $line ]->{ level } = $level;
+ $data->[ $line ]->{ title } = $title;
+ $data->[ $line ]->{ date_list } = $date_list;
+ $data->[ $line ]->{ status } = $status;
+ $data->[ $line ]->{ comment } = $comment;
}
$rh->close();
}
@@ -103,6 +119,50 @@ sub parse
}
+# Descriptions: parse the given string and return the date list as ARRAY_REF.
+# Arguments: OBJ($self) STR($s)
+# Side Effects: none
+# Return Value: ARRAY_REF
+sub _get_canonical_date_list
+{
+ my ($self, $s) = @_;
+
+ if ($s =~ /^([\/\d]+)-([\/\d]+)$/) {
+ my $first = $self->_canonical_date($1);
+ my $last = $self->_canonical_date($2);
+ return $self->_expand_date_list( $first, $last );
+ }
+ else {
+ my $d = $self->_canonical_date($s);
+ return [ $d ];
+ }
+}
+
+
+# Descriptions: return date list from $first to $last.
+# Arguments: OBJ($self) STR($first) STR($last)
+# Side Effects: none
+# Return Value: ARRAY_REF
+sub _expand_date_list
+{
+ my ($self, $first, $last) = @_;
+ my $r = [];
+
+ use Time::ParseDate;
+ my $first_sec = parsedate($first);
+ my $last_sec = parsedate($last);
+
+ for (my $sec = $first_sec; $sec <= $last_sec; $sec += 86400) {
+ use Mail::Message::Date;
+ my $date = new Mail::Message::Date $sec;
+ my $yyyy = $date->YYYYxMMxDD($sec);
+ push(@$r, $yyyy);
+ }
+
+ return $r;
+}
+
+
# Descriptions: return canonicalized date string.
# Arguments: OBJ($self) STR($date)
# Side Effects: none
@@ -189,11 +249,13 @@ sub build
use FML::Demo::Chart;
my $chart = new FML::Demo::Chart;
my $max_line = $#$data;
+ LINE:
for (my $line = 1; $line < $max_line; $line++) {
- my $level = $data->[ $line ]->{ level } || 1;
- my $title = $data->[ $line ]->{ title } || '';
- my $date = $data->[ $line ]->{ date } || '';
- my $comment = $data->[ $line ]->{ comment } || '';
+ my $level = $data->[ $line ]->{ level } || 1;
+ my $title = $data->[ $line ]->{ title } || '';
+ my $date_list = $data->[ $line ]->{ date_list } || [];
+ my $status = $data->[ $line ]->{ status } || '';
+ my $comment = $data->[ $line ]->{ comment } || '';
if ($level == 1) {
$chart->add($line, "item1", $title);
@@ -205,8 +267,19 @@ sub build
$chart->add($line, "item1", "");
}
- if ($date) {
- $chart->add($line, $date, "O");
+ if (@$date_list) {
+ my $mark = $self->get_mark_nl();
+ for my $day (@$date_list) {
+ $chart->add($line, $day, $mark);
+ }
+ }
+
+ if ($status) {
+ $chart->add($line, "status", $status);
+ }
+
+ if ($comment) {
+ $chart->add($line, "misc", $comment);
}
}
@@ -242,6 +315,34 @@ sub print_as_csv
}
+=head1 Japanese Specific Methods
+
+=head2 get_mark_nl()
+
+=cut
+
+
+# Descriptions: return mark.
+# Arguments: OBJ($self)
+# Side Effects: none
+# Return Value: STR
+sub get_mark_nl
+{
+ my ($self) = @_;
+ my $base_class = "FML::Demo::Language";
+ my $module = sprintf("%s::%s", $base_class, $global_language);
+ my $mark = 'O';
+ eval qq{
+ use $module;
+ my \$lang = new $module;
+ \$mark = \$lang->get_mark();
+ };
+ croak($@) if $@;
+
+ return( $mark || 'O' );
+}
+
+
if ($0 eq __FILE__) {
my $file = shift @ARGV;
my $proj = new FML::Demo::Project;