Scratchpad.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 120 CC 11 SCAR 34.7
CC
11
Cov
0%
update
72.0
load
20.0
new
2.0
CRAP 32.1
1 # E2::Scratchpad
2 # Jose M. Weeks <jose@joseweeks.com>
3 # 17 June 2003
4 #
5 # See bottom for pod documentation.
6  
7 package E2::Scratchpad;
8  
9 use 5.006;
10 use strict;
11 use warnings;
12 use Carp;
13 use E2::Ticker;
14  
15 our @ISA = ("E2::Ticker");
16 our $VERSION = "0.32";
17 our $DEBUG; *DEBUG = *E2::Interface::DEBUG;
18  
19 sub new {
20 my $arg = shift;
21 my $class = ref($arg) || $arg;
22  
23 my $self = $class->SUPER::new( @_ );
24  
25 $self->{text} = undef;
26 $self->{user} = undef;
27 $self->{shared} = undef;
28  
29 return $self;
30 }
31  
32 sub text { return $_[0]->{text} }
33 sub user { return $_[0]->{user} }
34 sub shared { return $_[0]->{shared} }
35  
36 sub load {
37 my $self = shift or croak "Usage: scratch_pad E2SCRATCHPAD [, USER ]";
38 my $user_id = shift;
39 my %opt;
40  
41 warn "E2::Scratchpad::load" if $DEBUG > 1;
42  
43 $opt{scratch} = $user_id if $user_id;
44  
45 my $handlers = {
46 'scratchtxt' => sub {
47 (my $a, my $b) = @_;
48 $self->{text} = $b->text;
49 $self->{user} = $b->{att}->{user};
50 $self->{shared} = $b->{att}->{user};
51 }
52 };
53  
54 $self->{text} = undef;
55 $self->{user} = undef;
56 $self->{shared} = undef;
57  
58 return $self->thread_then(
59 [
60 \&E2::Ticker::parse,
61 $self,
62 'scratch',
63 $handlers,
64 [], # dummy value for array
65 %opt
66 ],
67 sub { return $self->user ? 1 : 0 }
68 );
69 }
70  
71 sub update {
72 my $self = shift or croak "Usage: update E2SCRATCHPAD [ TEXT ] [, SHARE ]";
73 my $text = shift;
74 my $share = shift;
75  
76 warn "E2::Scratchpad::update" if $DEBUG > 1;
77
78 # Must be logged in AND either updating the text or the share
79 # (or both)
80  
81 if( ! $self->logged_in ) {
82 warn "Unable to update scratchpad: not logged in" if $DEBUG;
83 return undef;
84 }
85 if( ! defined $text && ! defined $share ) {
86 warn "Nothing to update" if $DEBUG;
87 return undef;
88 }
89  
90 my %req = (
91 node => 'E2 Scratch Pad',
92 skratchsubmit => 1,
93 sexisgood => 1,
94 submit => 'Update!'
95 );
96  
97 if( defined $text ) {
98 $req{skratch} = $text;
99 }
100  
101 if( defined $share ) {
102 # ...
103 }
104  
105 $self->thread_then(
106 [ \&E2::Interface::process_request, $self, %req ],
107 sub {
108 # FIXME: test for success
109 return 1;
110 }
111 );
112 }
113  
114 1;
115 __END__