| 1 | #=============================== Notepad.pm ================================== | ||||||||||||||
| 2 | # Filename: Notepad.pm | ||||||||||||||
| 3 | # Description: A notepad for random text messages. | ||||||||||||||
| 4 | # Original Author: Dale M. Amon | ||||||||||||||
| 5 | # Revised by: $Author: amon $ | ||||||||||||||
| 6 | # Date: $Date: 2008-08-28 23:20:19 $ | ||||||||||||||
| 7 | # Version: $Revision: 1.7 $ | ||||||||||||||
| 8 | # License: LGPL 2.1, Perl Artistic or BSD | ||||||||||||||
| 9 | # | ||||||||||||||
| 10 | #============================================================================= | ||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use Fault::Msg; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Fault::Logger; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | package Fault::Notepad; | ||||||||||||||
| 16 | 1 | ▶ | use vars qw{@ISA}; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 1 | @ISA = qw( UNIVERSAL ); | |||||||||||||
| 18 | |||||||||||||||
| 19 | #============================================================================= | ||||||||||||||
| 20 | # CLASS METHODS | ||||||||||||||
| 21 | #============================================================================= | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | ▶ | sub new ($) { | ||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 24 | 0 | my ($class) = @_; | |||||||||||||
| 25 | 0 | my $self = bless {}, $class; | |||||||||||||
| 26 | 0 | $self->{'notes'} = []; | |||||||||||||
| 27 | 0 | return $self; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | #============================================================================= | ||||||||||||||
| 31 | # INSTANCE METHODS | ||||||||||||||
| 32 | #============================================================================= | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | ▶ | sub add ($$) { | ||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 35 | 0 | my ($s,$n) = @_; | |||||||||||||
| 36 | |||||||||||||||
| 37 | 0 | ▶ | if ($::DEBUG) {Fault::Logger->arg_check_noref ($n,"Textline") or return $s;} | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | push @{$s->{'notes'}}, Fault::Msg->new ($n,'NOTE','info'); | |||||||||||||
| 40 | 0 | return $s; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | #----------------------------------------------------------------------------- | ||||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | sub addObject ($$) { | ||||||||||||
|
Subroutine
addObject: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 46 | 0 | my ($s,$msg) = @_; | |||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | ▶ | if ($::DEBUG) {Fault::Logger->arg_check_isa ($msg,"Fault::Msg") | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 49 | or return $s;} | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | push @{$s->{'notes'}}, $msg; | |||||||||||||
| 52 | 0 | return $s; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | #----------------------------------------------------------------------------- | ||||||||||||||
| 56 | |||||||||||||||
| 57 | 0 | ▶ | sub merge ($$) { | ||||||||||||
|
Subroutine
merge: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 58 | 0 | my ($s,$s2) = @_; | |||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | ▶ | if ($::DEBUG) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 0 | ▶ | Fault::Logger->arg_check_isa ($s2,"Notepad","notepad2") or return $s; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | } | ||||||||||||||
| 63 | 0 | push @{$s->{'notes'}}, @{$s2->{'notes'}}; | |||||||||||||
| 64 | 0 | return $s; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | #----------------------------------------------------------------------------- | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | ▶ | sub count ($) {my ($s) = @_; $#{$s->{'notes'}}+1;} | ||||||||||||
|
Subroutine
count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | ▶ | sub print ($) {shift->fprint (*STDOUT);} | ||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub fprint ($\*) { | ||||||||||||
|
Subroutine
fprint: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 74 | 0 | my ($s,$fh) = @_; foreach (@{$s->{'notes'}}) {print $fh $_->msg . "\n";} $s;} | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | sub sprint ($) { | ||||||||||||
|
Subroutine
sprint: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 77 | 0 | my ($s) = @_; my $str=""; | |||||||||||||
| 78 | 0 | foreach (@{$s->{'notes'}}) {$str .= sprintf $_->msg . "\n";} $str;} | |||||||||||||
| 79 | |||||||||||||||
| 80 | #============================================================================= | ||||||||||||||
| 81 | # POD DOCUMENTATION | ||||||||||||||
| 82 | #============================================================================= | ||||||||||||||
| 83 | # You may extract and format the documention section with the 'perldoc' cmd. | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 NAME | ||||||||||||||
| 86 | |||||||||||||||
| 87 | Fault::Notepad - A notepad for random text messages. | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head1 SYNOPSIS | ||||||||||||||
| 90 | |||||||||||||||
| 91 | use Fault::Notepad; | ||||||||||||||
| 92 | $obj = Fault::Notepad->new; | ||||||||||||||
| 93 | $obj = $obj->add ($text); | ||||||||||||||
| 94 | $obj = $obj->addObject ($msg); | ||||||||||||||
| 95 | $obj = $obj->merge ($obj2); | ||||||||||||||
| 96 | $obj = $obj->print; | ||||||||||||||
| 97 | $cnt = $obj->count; | ||||||||||||||
| 98 | $obj = $obj->fprint ($fh); | ||||||||||||||
| 99 | $str = $obj->sprint; | ||||||||||||||
| 100 | |||||||||||||||
| 101 | =head1 Inheritance | ||||||||||||||
| 102 | |||||||||||||||
| 103 | UNIVERSAL | ||||||||||||||
| 104 | |||||||||||||||
| 105 | =head1 Description | ||||||||||||||
| 106 | |||||||||||||||
| 107 | A notepad is a container for random text messages. Notes are added to a | ||||||||||||||
| 108 | list in the sequence recieved and once written are not modifiable. | ||||||||||||||
| 109 | |||||||||||||||
| 110 | This is a very early form of the class and it does very little at present | ||||||||||||||
| 111 | other than append Fault::Msg objects to it's internal list and dump text | ||||||||||||||
| 112 | from them on demand. | ||||||||||||||
| 113 | |||||||||||||||
| 114 | It is a container for text generated deep in a program which will allow it | ||||||||||||||
| 115 | to be collected and returned to the top level or wherever it may be useful. | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =head1 Examples | ||||||||||||||
| 118 | |||||||||||||||
| 119 | use Fault::Notepad; | ||||||||||||||
| 120 | use Fault::Msg; | ||||||||||||||
| 121 | my $obj = Fault::Notepad->new; | ||||||||||||||
| 122 | my $obj2 = Fault::Notepad->new; | ||||||||||||||
| 123 | my $msg = Fault::Msg->("abridging freedom of speech...\n"); | ||||||||||||||
| 124 | |||||||||||||||
| 125 | $obj->add ("Congress shall pass no law "); | ||||||||||||||
| 126 | $obj2->addObject ($msg); | ||||||||||||||
| 127 | $obj->merge ($obj2); | ||||||||||||||
| 128 | $obj->print; | ||||||||||||||
| 129 | |||||||||||||||
| 130 | open $fh, ">notepad.tmp"; | ||||||||||||||
| 131 | $obj->fprint ($fh); | ||||||||||||||
| 132 | close $fh; | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =head1 Class Variables | ||||||||||||||
| 135 | |||||||||||||||
| 136 | None. | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =head1 Instance Variables | ||||||||||||||
| 139 | |||||||||||||||
| 140 | None. | ||||||||||||||
| 141 | |||||||||||||||
| 142 | =head1 Class Methods | ||||||||||||||
| 143 | |||||||||||||||
| 144 | =over 4 | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =item B<$obj = Fault::Notepad-E<gt>new> | ||||||||||||||
| 147 | |||||||||||||||
| 148 | Create instances of Notepad. | ||||||||||||||
| 149 | |||||||||||||||
| 150 | =head1 Instance Methods | ||||||||||||||
| 151 | |||||||||||||||
| 152 | =over 4 | ||||||||||||||
| 153 | |||||||||||||||
| 154 | =item B<$obj = $obj-E<gt>add ($note)> | ||||||||||||||
| 155 | |||||||||||||||
| 156 | Append a textual note to the notepad. | ||||||||||||||
| 157 | |||||||||||||||
| 158 | =item B<$obj = $obj-E<gt>add ($obj)> | ||||||||||||||
| 159 | |||||||||||||||
| 160 | Append an Fault::Msg object containing a textual note to the notepad. | ||||||||||||||
| 161 | the current time; if the object has digital signatures, create one. | ||||||||||||||
| 162 | |||||||||||||||
| 163 | =item B<$cnt = $obj-E<gt>count> | ||||||||||||||
| 164 | |||||||||||||||
| 165 | Returns a count of the items on the notepad. | ||||||||||||||
| 166 | |||||||||||||||
| 167 | =item B<$obj = $obj-E<gt>fprint ($fh)> | ||||||||||||||
| 168 | |||||||||||||||
| 169 | Print contents of Notepad verbatim to file. | ||||||||||||||
| 170 | |||||||||||||||
| 171 | =item B<$obj = $obj-E<gt>merge ($other)> | ||||||||||||||
| 172 | |||||||||||||||
| 173 | Append the contents of the argument notepad object to this notepad. | ||||||||||||||
| 174 | |||||||||||||||
| 175 | =item B<$obj = $obj-E<gt>print> | ||||||||||||||
| 176 | |||||||||||||||
| 177 | Print contents of Notepad verbatim to stdout. | ||||||||||||||
| 178 | |||||||||||||||
| 179 | =item B<$str = $obj-E<gt>sprint> | ||||||||||||||
| 180 | |||||||||||||||
| 181 | Print contents of Notepad verbatim to a string. | ||||||||||||||
| 182 | |||||||||||||||
| 183 | =back 4 | ||||||||||||||
| 184 | |||||||||||||||
| 185 | =head1 Private Class Method | ||||||||||||||
| 186 | |||||||||||||||
| 187 | None. | ||||||||||||||
| 188 | |||||||||||||||
| 189 | =head1 Private Instance Methods | ||||||||||||||
| 190 | |||||||||||||||
| 191 | None. | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =head1 Errors and Warnings | ||||||||||||||
| 194 | |||||||||||||||
| 195 | None. | ||||||||||||||
| 196 | |||||||||||||||
| 197 | =head1 KNOWN BUGS | ||||||||||||||
| 198 | |||||||||||||||
| 199 | See TODO. | ||||||||||||||
| 200 | |||||||||||||||
| 201 | =head1 SEE ALSO | ||||||||||||||
| 202 | |||||||||||||||
| 203 | Fault::Logger, Fault::Msg. | ||||||||||||||
| 204 | |||||||||||||||
| 205 | =head1 AUTHOR | ||||||||||||||
| 206 | |||||||||||||||
| 207 | Dale Amon <amon@vnl.com> | ||||||||||||||
| 208 | |||||||||||||||
| 209 | =cut | ||||||||||||||
| 210 | |||||||||||||||
| 211 | #============================================================================= | ||||||||||||||
| 212 | # CVS HISTORY | ||||||||||||||
| 213 | #============================================================================= | ||||||||||||||
| 214 | # $Log: Notepad.pm,v $ | ||||||||||||||
| 215 | # Revision 1.7 2008-08-28 23:20:19 amon | ||||||||||||||
| 216 | # perldoc section regularization. | ||||||||||||||
| 217 | # | ||||||||||||||
| 218 | # Revision 1.6 2008-08-17 21:56:37 amon | ||||||||||||||
| 219 | # Make all titles fit CPAN standard. | ||||||||||||||
| 220 | # | ||||||||||||||
| 221 | # Revision 1.5 2008-07-28 10:57:37 amon | ||||||||||||||
| 222 | # Dropped last of tsag/dsig; new addObject method; sprint bugfix; newlines added to prints. | ||||||||||||||
| 223 | # | ||||||||||||||
| 224 | # Revision 1.4 2008-07-24 21:17:24 amon | ||||||||||||||
| 225 | # Moved all todo notes to elsewhere; made Stderr the default delegate instead | ||||||||||||||
| 226 | # of Stdout. | ||||||||||||||
| 227 | # | ||||||||||||||
| 228 | # Revision 1.3 2008-07-24 19:27:51 amon | ||||||||||||||
| 229 | # Fix edit error in Notepad. | ||||||||||||||
| 230 | # | ||||||||||||||
| 231 | # Revision 1.2 2008-07-24 19:11:29 amon | ||||||||||||||
| 232 | # Notepad now uses Fault::Msg class which moves all the timestamp and | ||||||||||||||
| 233 | # digitalsig issues to Msg. | ||||||||||||||
| 234 | # | ||||||||||||||
| 235 | # Revision 1.1 2008-07-22 14:32:17 amon | ||||||||||||||
| 236 | # Added Notepad and Delegate::Stderr classes | ||||||||||||||
| 237 | # | ||||||||||||||
| 238 | # 20080715 Dale Amon <amon@vnl.com> | ||||||||||||||
| 239 | # Created. | ||||||||||||||
| 240 | 1 | 1; | |||||||||||||