blib/lib/Text/DeSupercite.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 91.6% 11 / 12 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 88.1% 67 / 76 CC 13 SCAR 17.5
CC
13
Cov
92%
_desupercite_aux
10.2
desupercite
3.0
_lenient
2.0
CRAP 5.8
↑ Summary
1 package Text::DeSupercite;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Text::Quoted;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use vars qw(@EXPORT_OK $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 @EXPORT_OK = qw(desupercite);
10  
11 2 $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 <foo@foo.com> 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<all> 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 <simon@thegestalt.org>
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<Text::Quoted>, L<desupercite>
102  
103 =cut
104  
105 8 ▶sub desupercite ($;$) {
Subroutine desupercite: called CC=3 SCAR=11.1
Pod undocumented
106  
107 8 ▶ my $text = shift || return "";
Condition50%1/2
shift() || (return '')
l!l
80
MC/DC0%0/1
shift() || (return '')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
108 8 ▶ my $merciless = shift || 0;
Condition100%2/2
shift() || 0
l!l
44
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
109  
110  
111 8 return _desupercite_aux(extract($text),$merciless);
112  
113 }
114  
115  
116 112 ▶sub _desupercite_aux($$) {
Subroutine _desupercite_aux: called CC=10 SCAR=23.2
117 112 ▶ my $node = shift || return "";
Condition50%1/2
shift() || (return '')
l!l
1120
MC/DC0%0/1
shift() || (return '')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
118 112 ▶ my $merciless = shift || 0; # paranoia, paranoia, everybody's coming to get you
Condition100%2/2
shift() || 0
l!l
5656
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
119  
120 112 ▶ if (ref $node eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node eq 'ARRAY') { } 40 72 112
elsif (ref $node eq 'HASH') { } 72 0 72
121 40 my $ret="";
122 40 $ret.=_desupercite_aux($_, $merciless) for (@$node);
123 40 return $ret;
124  
125  
126 } elsif (ref $node eq 'HASH') {
127 72 ▶ return "\n" if $node->{empty};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"empty"} 24 48 72
128  
129 48 ▶ if (!defined $node->{quoter} || $node->{quoter} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $node->{'quoter'} or $node->{'quoter'} eq '') { } 24 24 48
Condition66%2/3
not defined $node->{"quoter"} or $node->{"quoter"} eq ""
l!l&&r!l&&!r
02424
MC/DC50%1/2
not defined $node->{"quoter"} or $node->{"quoter"} eq ""
not defined $node->{"quoter"} $node->{"quoter"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $node->{"quoter"}B= $node->{"quoter"} eq ""
ABresult
1X1
011
000
130 24 return $node->{raw}."\n";
131 } else {
132 my $new = join ' ',
133 30 ▶ map { ($merciless)?_merciless($_):_lenient($_) }
Branch: 1 branch
BranchTrueFalseTotal
$merciless ? : 15 15 30
134 split /\s+/,
135 24 $node->{quoter};
136
137 24 $node->{raw} =~ s!^\Q$node->{quoter}!$new!mg;
138 24 return $node->{raw}."\n";
139 }
140 } else {
141 0 die "Eeeek unknown node type - ".(ref $node)."\n";
142 }
143
144  
145 }
146  
147  
148 15 ▶sub _merciless {
Subroutine _merciless: called CC=1 SCAR=0.0
149 15 return '>';
150 }
151  
152 15 ▶sub _lenient {
Subroutine _lenient: called CC=2 SCAR=6.9
153 15 ▶ return ($_[0] =~ /^[\w\d]+\>/i)? '>' : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^[\w\d]+\>/i ? : 5 10 15
154 }
155  
156  
157 2 1;
↑ Summary