blob: 5f63c11af3a7c970d9b93aa20b45283a03de4077 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#-*- perl -*-
#
# Copyright (C) 2001 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.
#
# $Id$
# $FML$
#
package FML::Article;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK);
use Carp;
use FML::Log qw(Log);
require Exporter;
# Descriptions: constructor
# Arguments: $self $curproc
# Side Effects: none
# Return Value: FML::Article object
sub new
{
my ($self, $curproc) = @_;
my ($type) = ref($self) || $self;
my $me = {};
_setup_article_template($curproc);
$me->{ curproc } = $curproc;
return bless $me, $type;
}
# Descriptions: prepare article template to distribute
# Arguments: $self $curproc
# Side Effects: build $curproc->{ article }
# Return Value: none
sub _setup_article_template
{
my ($curproc) = @_;
# setup article to distribute
my $msg = $curproc->{'incoming_message'};
# create an article template by duplicating the incoming message
$curproc->{ article }->{ header } = $msg->{'header'}->dup();
$curproc->{ article }->{ body } = $msg->{'body'};
}
# Descriptions: determine article id (sequence number)
# Arguments: $self
# Side Effects: record the current article sequence number
# Return Value: number (sequence identifier)
sub increment_id
{
my ($self) = @_;
my $curproc = $self->{ curproc };
my $config = $curproc->{ config };
my $pcb = $curproc->{ pcb };
my $seq_file = $config->{ sequence_file };
use FML::SequenceFile;
my $sfh = new FML::SequenceFile { sequence_file => $seq_file };
my $id = $sfh->increment_id;
if ($sfh->error) { Log( $sfh->error ); }
# save $id in pcb (process control block) and return $id
$pcb->set('article', 'id', $id);
$id;
}
sub id
{
my ($self) = @_;
my $curproc = $self->{ curproc };
my $pcb = $curproc->{ pcb };
return $pcb->get('article', 'id');
}
# Descriptions: spool in the article
# Arguments: $self $curproc
# Side Effects:
# Return Value: none
sub spool_in
{
my ($self, $id) = @_;
# configurations
my $curproc = $self->{ curproc };
my $config = $curproc->{ config };
my $spool_dir = $config->{ spool_dir };
if ( $config->yes( 'use_spool' ) ) {
unless (-d $spool_dir) {
use File::Path;
mkpath( $spool_dir, 0, 0700 );
}
my $file = $spool_dir . "/" . $id;
use FileHandle;
my $fh = new FileHandle;
$fh->open($file, "w");
if (defined $fh) {
$curproc->{ article }->{ header }->print($fh);
print $fh "\n";
$curproc->{ article }->{ body }->raw_print($fh);
$fh->close;
Log("Article $id");
}
}
else {
Log("not spool article");
}
}
=head1 NAME
FML::Article - article manipulation components
=head1 SYNOPSIS
... not yet documented ...
=head1 DESCRIPTION
... not yet documented ...
=head1 AUTHOR
Ken'ichi Fukamachi
=head1 COPYRIGHT
Copyright (C) 2001 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::Article.pm appeared in fml5.
=cut
1;
|