/[suikacvs]/perl/lib/Chat/Suika.pm
Suika

Contents of /perl/lib/Chat/Suika.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Mon Dec 24 08:13:56 2001 UTC (22 years, 11 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
2001-12-24  wakaba <wakaba@suika.fam.cx>

	* M17N/: New directory.

1 wakaba 1.1 ## -*- Perl -*- -*- Coding: euc-jisx0213 -*-
2    
3     =head1 NAME
4    
5     Chat::Suika
6    
7     =head1 DESCRIPTION
8    
9     SuikaChat -- SuikaChat format.
10    
11     =cut
12    
13     use strict;
14     package Chat::Suika;
15     use vars qw($VERSION);
16     $VERSION = '1.01';
17    
18     sub open($$) {
19     my $class = shift;
20     my $file = shift;
21    
22     my @CHAT;
23     if (open CHAT, $file) {@CHAT = <CHAT>; close CHAT}
24    
25     bless {file => $file, data => \@CHAT}, $class;
26     }
27    
28     sub reopen($) {
29     my $self = shift;
30     my @CHAT;
31     if (CORE::open(CHAT, $self->{file})) {@CHAT = <CHAT>; close CHAT}
32     $self->{data} = \@CHAT;
33     $self;
34     }
35    
36     sub say($%) {
37     my $self = shift;
38     my %saying = @_;
39     return $self unless $saying{text};
40     for ($saying{keys %saying}) {tr/\x1f\x0d\x0a//d}
41     $saying{time} = time unless $saying{time};
42     $saying{name} = 'foo' unless $saying{name};
43     for ('namecolor', 'textcolor') {
44     $saying{$_}
45     = 'rgb('.int(rand(127)).','.int(rand(127)).','.int(rand(127)).')'
46     if $saying{$_} eq 'random';
47     }
48     my $newtext;
49     for (keys %saying) {$newtext .= $_."\x1f".$saying{$_}."\x1f"}
50     $newtext .= "\n";
51    
52     if (CORE::open(CHAT, '>> '. $self->{file})) {
53     print CHAT $newtext;
54     close CHAT}
55     $self;
56     }
57    
58     sub reverse($) {
59     my $self = shift;
60     @{$self->{data}} = CORE::reverse @{$self->{data}};
61     $self;
62     }
63    
64     sub get($%) {
65     my $self = shift;
66     my %param = @_;
67     $param{start} = 0 unless $param{start};
68     $param{end} = $#{$self->{data}} unless $param{end};
69     $param{end} = $param{start} if $param{end} < $param{start};
70     my @ret;
71    
72     for (my $i = $param{start}; $i <= $param{end}; $i++) {
73     my %val = split /[\x1f\x0d\x0a]/, ${$self->{data}}[$i];
74     push @ret, \%val;
75     }
76    
77     wantarray? @ret: \@ret;
78     }
79    
80     =head1 CHANGE
81    
82     2001-11-10 wakaba <wakaba@suika.fam.cx>
83    
84     * use strict.
85    
86     2001-05-11 wakaba <wakaba@suika.fam.cx>
87    
88     * New File.
89    
90     =cut
91    
92     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24