Prepare for git repository
[spider.git] / perl / Editable.pm
1 #
2 # A module to allow a user to create and (eventually) edit arrays of
3 # text and attributes
4 #
5 # This is used for creating mail messages and user script files
6 #
7 # It may be sub-classed
8 #
9 # Copyright (c) 2001 Dirk Koopman G1TLH
10 #
11 # $Id$
12 #
13
14 package Editable;
15
16 use strict;
17
18 use DXChannel;
19 use DXDebug;
20 use BadWords;
21
22 sub new
23 {
24         my $pkg = shift;
25         my $class = ref $pkg || $pkg;
26         
27         return {@_}, $class; 
28 }
29
30 sub copy
31 {
32         my $self = shift;
33         return $self->new(%$self);
34 }
35
36 sub addline
37 {
38         my $self = shift;
39         my $dxchan = shift;
40         my $line = shift;
41         
42         if (my @ans = BadWord::check($line)) {
43                 return ($dxchan->msg('e17', @ans));
44         }
45         push @{$self->{lines}}, $line;
46         return ();
47 }
48
49 sub modline
50 {
51         my $self = shift;
52         my $dxchan = shift;
53         my $no = shift;
54         my $line = shift;
55
56         if (my @ans = BadWord::check($line)) {
57                 return ($dxchan->msg('e17', @ans));
58         }
59     ${$self->{lines}}[$no] = $line;
60         return ();
61 }
62
63 sub lines
64 {
65         my $self = shift;
66         return exists $self->{lines} ? (@{$self->{lines}}) : ();
67 }
68
69 sub nolines
70 {
71         my $self = shift;
72         return exists $self->{lines} ? scalar @{$self->{lines}} : 0;
73 }
74
75 1;