lib/MojoMojo/Formatter/IRCLog.pm

filter: Statementstmt 93.7% 45 / 48 Branchbran 88.8% 16 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 92.9% 66 / 71 CC 13 SCAR 24.4
CC
13
Cov
92%
format_content
13.1
BEGIN
1.0
format_content_order
1.0
CRAP 11.5
« lib/MojoMojo/Controller/Root.pm ↑ Summary lib/MojoMojo/Formatter/Amazon.pm »
1 package MojoMojo::Formatter::IRCLog;
2  
3 27 ▶use parent qw/MojoMojo::Formatter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 MojoMojo::Formatter::IRCLog - format part of content as an IRC log
8  
9 =head1 DESCRIPTION
10  
11 This formatter will format content between {{irc}} and {{end}} as
12 an IRC log
13  
14 =head1 METHODS
15  
16 =head2 format_content_order
17  
18 Format order can be 1-99. The IRC log formatter runs on 14,
19 just before the main formatter.
20  
21 =cut
22  
23 992 ▶sub format_content_order { 14 }
Subroutine format_content_order: called CC=1 SCAR=0.0
Pod documented
24  
25 =head2 format_content
26  
27 Calls the formatter. Takes a ref to the content as well as the
28 context object.
29  
30 =cut
31  
32 133 ▶sub format_content {
Subroutine format_content: called CC=13 SCAR=25.7
Pod documented
33 133 my ( $class, $content ) = @_;
34 133 my ( $in_log, %nicks, $longline, @newlines );
35  
36 133 my @lines = split( /\n/, $$content );
37 133 $$content = "";
38 133 my $start_re=$class->gen_re(qr/irc/);
39 133 my $end_re=$class->gen_re(qr/end/);
40  
41 133 foreach my $line (@lines) {
42 702 ▶ if ($in_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_log) { } 23 679 702
43 23 ▶ if ( $line =~ $end_re ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /$end_re/) { } 10 13 23
elsif ($line =~ /^[\d:]*\s*<[+\%\@ ]?(.*?)>\s*(.*)/) { } 10 3 13
44 10 $in_log = 0;
45 10 ▶ if ($longline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($longline) 10 0 10
46 10 $longline .= "</dd>";
47 10 push( @newlines, $longline );
48 10 $longline = "";
49 }
50 10 push @newlines, $line;
51 }
52 elsif ( $line =~ /^[\d:]*\s*<[+\%\@ ]?(.*?)>\s*(.*)/ ) {
53 10 ▶ if ($longline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($longline) 0 10 10
54 0 $longline .= "</dd>";
55 0 push( @newlines, $longline );
56 0 $longline = "";
57 }
58 10 $nicks{$1} = 1;
59 10 $longline = "<dt>$1</dt>\n<dd>$2";
60 }
61 else {
62 3 $line =~ s/^\s*/ /;
63 3 $longline .= $line;
64 }
65 }
66 else {
67 679 ▶ if ( $line =~ $start_re ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$start_re/) { } 10 669 679
68 10 push @newlines, $line;
69 10 $in_log = 1;
70 }
71 else {
72 669 push( @newlines, $line );
73 }
74 }
75 }
76 133 foreach my $line (@newlines) {
77 699 ▶ if ($in_log) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_log) { } 20 679 699
78 20 ▶ if ( $line =~ $end_re ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$end_re/) { } 10 10 20
79 10 $in_log = 0;
80  
81 # end the dl and the section not handled by textile
82 10 $$content .= "</dl>\n==\n";
83 }
84 else {
85 10 my $count = 0;
86 10 my @colours=( 'navy', 'green' , 'maroon', 'blue', 'lime', 'red', 'silver', 'gray', 'teal', 'olive', 'purple', 'fuchsia' );
87 10 my $counter;
88 10 foreach my $nick ( keys %nicks ) {
89 10 $colour=$colours[$counter++];
90 10 $count += ( $line =~ s!(<d.>)$nick(</d.>)!$1<font color="$colour">[[$nick]]</font>$2!g );
91 }
92 10 $$content .= "$line\n";
93 }
94 }
95 else {
96 679 ▶ if ( $line =~ $start_re ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$start_re/) { } 10 669 679
97 10 $in_log = 1;
98  
99 # start a definition list in a section not handled by
100 # textile
101 10 $$content .= "==\n<dl>\n";
102 }
103 else {
104 669 $$content .= "$line\n";
105 }
106 }
107 }
108 }
109  
110 =head1 SEE ALSO
111  
112 L<MojoMojo> and L<Module::Pluggable::Ordered>.
113  
114 =head1 AUTHORS
115  
116 Martijn van Beers <martijn@eekeek.org>
117  
118 =head1 LICENSE
119  
120 This library is free software. You can redistribute it and/or modify
121 it under the same terms as Perl itself.
122  
123 =cut
124  
125 27 1;
« lib/MojoMojo/Controller/Root.pm ↑ Summary lib/MojoMojo/Formatter/Amazon.pm »