File Coverage

blib/lib/Text/DeSupercite.pm
Criterion Covered Total %
statement 33 34 97.0
branch 11 12 91.6
condition 8 11 72.7
subroutine 9 9 100.0
pod 0 1 0.0
total 61 67 91.0


line stmt bran cond sub pod time code
1             package Text::DeSupercite;
2              
3 2     2   1499 use strict;
  2         4  
  2         65  
4 2     2   1792 use Text::Quoted;
  2         151057  
  2         168  
5 2     2   51 use Exporter;
  2         4  
  2         76  
6 2     2   11 use vars qw(@EXPORT_OK $VERSION);
  2         4  
  2         139  
7 2     2   13 use base qw(Exporter);
  2         5  
  2         1557  
8              
9             @EXPORT_OK = qw(desupercite);
10              
11             $VERSION = '0.6';
12              
13             sub desupercite ($;$);
14             sub _desupercite_aux ($$);
15              
16             =pod
17              
18             =head1 NAME
19              
20             Text::DeSupercite - remove supercite quotes and other non-standard quoting from text
21              
22             =head1 SYNOPSIS
23              
24             use Text::DeSupercite qw/desupercite/;
25              
26             # just convert supercite quotes to '>'s
27             $text = desupercite($mail->body());
28              
29             # or convert *all* quot characters that aren't '>'s
30             $text = desupercite($mail->body(),1);
31              
32             # set it back again
33             $mail->body_set($text);
34              
35            
36             =head1 DESCRIPTION
37              
38             Supercite is a Emacs Gnus package (http://www.gnus.org/) for providing a more
39             err ... comprehensive ... form of quoting which tends to look like
40              
41             >>>>> "Foo" == Foo writes:
42             >> blah blah blah blah blah blah blah blah blah blah blah blah blah blah
43             >> blah blah blah blah blah blah blah blah blah blah blah blah blah blah
44              
45             Foo> yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak
46             Foo> yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak
47             Foo> yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak yak
48              
49              
50             which annoys quite a lot of people who find it too noisy.
51              
52             There's also people who quote like this
53              
54             | this is a quote
55            
56             this is not
57              
58             which annoys another load of people. Mostly the two sets of annoyed people intersect.
59             Which is quite understandable.
60              
61             This module takes a simplistic approach to removing these forms of quoting and
62             replacing them with the more normal
63              
64             > this is a quote
65              
66             this is not
67              
68             > > this is a quote of a quote
69              
70             style.
71              
72             It has two modes, harsh and lenient. Lenient just desupercites. Harsh normalises
73             B quoting.
74              
75             =head1 BUGS
76              
77             Non known but I haven't really hunted out pathological cases of superciting so
78             if you find one then please let me know.
79              
80             It currently fails to desupercite stuff looking like
81              
82             Name1> some quote
83              
84             this is a bug in Text::Quoted. There's a patch included with this module to fix it
85             if it's not fixed by Simon Cozens soon.
86              
87             =head1 AUTHOR
88              
89             Simon Wistow
90              
91             =head1 COPYRIGHT
92              
93             (c)opyright Simon Wistow, 2003
94              
95             Distributed under the same terms as Perl itself.
96              
97             This software is under no warranty and will probably ruin your life, kill your friends, burn your house and bring about the apocalypse
98              
99             =head1 SEE ALSO
100              
101             L, L
102              
103             =cut
104              
105             sub desupercite ($;$) {
106              
107 8   50 8 0 1274 my $text = shift || return "";
108 8   100     30 my $merciless = shift || 0;
109              
110              
111 8         22 return _desupercite_aux(extract($text),$merciless);
112              
113             }
114              
115              
116             sub _desupercite_aux($$) {
117 112   50 112   6192 my $node = shift || return "";
118 112   100     274 my $merciless = shift || 0; # paranoia, paranoia, everybody's coming to get you
119              
120 112 100       269 if (ref $node eq 'ARRAY') {
    50          
121 40         48 my $ret="";
122 40         103 $ret.=_desupercite_aux($_, $merciless) for (@$node);
123 40         155 return $ret;
124              
125              
126             } elsif (ref $node eq 'HASH') {
127 72 100       186 return "\n" if $node->{empty};
128              
129 48 100 66     234 if (!defined $node->{quoter} || $node->{quoter} eq '') {
130 24         83 return $node->{raw}."\n";
131             } else {
132 30 100       71 my $new = join ' ',
133 24         53 map { ($merciless)?_merciless($_):_lenient($_) }
134             split /\s+/,
135             $node->{quoter};
136            
137 24         310 $node->{raw} =~ s!^\Q$node->{quoter}!$new!mg;
138 24         117 return $node->{raw}."\n";
139             }
140             } else {
141 0         0 die "Eeeek unknown node type - ".(ref $node)."\n";
142             }
143            
144              
145             }
146              
147              
148             sub _merciless {
149 15     15   35 return '>';
150             }
151              
152             sub _lenient {
153 15 100   15   67 return ($_[0] =~ /^[\w\d]+\>/i)? '>' : $_[0];
154             }
155              
156              
157             1;