f4bea483e68bd14ec79aa51aec20b17c25084c7d
[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 vars qw($VERSION $BRANCH);
19 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
20 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
21 $main::build += $VERSION;
22 $main::branch += $BRANCH;
23
24 use DXChannel;
25 use DXDebug;
26 use BadWords;
27
28 sub new
29 {
30         my $pkg = shift;
31         my $class = ref $pkg || $pkg;
32         
33         return {@_}, $class; 
34 }
35
36 sub copy
37 {
38         my $self = shift;
39         return $self->new(%$self);
40 }
41
42 sub addline
43 {
44         my $self = shift;
45         my $dxchan = shift;
46         my $line = shift;
47         
48         if (my @ans = BadWord::check($line)) {
49                 return ($dxchan->msg('e17', @ans));
50         }
51         push @{$self->{lines}}, $line;
52         return ();
53 }
54
55 sub modline
56 {
57         my $self = shift;
58         my $dxchan = shift;
59         my $no = shift;
60         my $line = shift;
61
62         if (my @ans = BadWord::check($line)) {
63                 return ($dxchan->msg('e17', @ans));
64         }
65     ${$self->{lines}}[$no] = $line;
66         return ();
67 }
68
69 sub lines
70 {
71         my $self = shift;
72         return exists $self->{lines} ? (@{$self->{lines}}) : ();
73 }
74
75 sub nolines
76 {
77         my $self = shift;
78         return exists $self->{lines} ? scalar @{$self->{lines}} : 0;
79 }
80
81 1;