blib/lib/Text/Format/Interview.pm

filter: Statementstmt 100% 35 / 35 Branchbran 62.5% 5 / 8 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 2 / 2 Podpod 100% 1 / 1 totaltotal 94.2% 49 / 52 CC 11 SCAR 23.2
CC
11
Cov
94%
process
11.0
BEGIN
1.0
CRAP 10.2
↑ Summary
1 package Text::Format::Interview;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Text::Format::Interview - Take a text interview transcript and format to html.
7  
8 =head1 VERSION
9  
10 Version 0.03
11  
12 =cut
13  
14 2 our $VERSION = '0.03';
15  
16 =head1 SYNOPSIS
17  
18 use Text::Format::Interview;
19  
20 my $txt = Text::Format::Interview->new();
21 my $html = $txt->process($string);
22  
23  
24 Converts text of the form:
25  
26 # Interview between Fred Flintstone and Barney Rubble, 3rd April, 2000 BC
27  
28 Fred: [00:00:00]
29 So, Barney, when did you decide to become a Flintstone?
30  
31 Barney: [00:00:10]
32 Well Fred, I'm not actually a Flintstone, my surname is Rubble and I live in Bedrock.
33  
34 Into HTML, something like:
35  
36 # Interview between Fred Flintstone and Barney Rubble, 3rd April, 2000 BC
37  
38 <h2>Fred: [00:00:00]</h2>
39 <p>So, Barney, when did you decide to become a Flintstone?</p>
40  
41 This is intended as a pre-processor, so the header is using markdown here, but could equally be html.
42  
43 Alternatively if you specify a comma separated list of "interviewers" and
44 "interviewees" at the top of the file to be processed, you'll get some css
45 classes as well:
46  
47 # Interview between Fred Flintstone and Barney Rubble, 3rd April, 2000 BC
48 interviewer: fred,wilma
49 interviewee: barney,betty
50  
51 Fred: [00:00:00]
52 So what's it like to be a flintstone?
53  
54 Barney: [00:00:05]
55 I'm not a Flintstone, I'm a Rubble. What do you think Betty?
56  
57 Betty: [00:00:10]
58 Yes Fred, you're confused.
59  
60 Wilma: [00:00:15]
61 I'm so terribly embarrassed by my husband.
62  
63 Which ought to render to:
64  
65 # Interview between Fred Flintstone and Barney Rubble, 3rd April, 2000 BC
66  
67 <p>interviewer: fred, wilma <br>
68 interviewee: barney, betty <br></p>
69  
70 <h2 class="interviewer">Fred: [00:00:00]</h2>
71 <p>So what's it like to be a flintstone?</p>
72  
73 <h2 class="interviewee">Barney: [00:00:05]</p>
74 <p>I'm not a Flintstone, I'm a Rubble. What do you think Betty?</p>
75  
76 This gives us the ability to put pretty colours in the interview transcript
77 with CSS, something like this:
78  
79 h2.interviewer > p { color: red }
80  
81 (or something far more tortorous if you need to Internet Explorer 6 support ...)
82  
83 =head1 FUNCTIONS
84  
85 =head2 process
86  
87 Takes the text, and spits out the html.
88  
89 =cut
90  
91 2 ▶sub process {
Subroutine process: called CC=11 SCAR=24.0
Pod documented
92 2 my ($self, $content) = @_;
93 2 my $rendered = '';
94 # first let's make sure our newlines are consistent for the current platform.
95 # regex ripped out of the cpan module File::LocalizeNewlines
96 2 $content =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
97 2 my @content = split /\n\n/, $content;
98 2 ▶ shift @content if $content[0] =~ /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if $content[0] =~ /^$/ 0 2 2
99 2 my ($interviewer) = $content[0] =~ /interviewer:\s?(.*)$/mi;
100 2 ▶ $interviewer ||='';
Condition100%2/2
$interviewer ||= ""
l!l
11
MC/DC100%1/1
$interviewer ||= ""
$interviewer
Truth table100%2/2
A
A= $interviewer
Aresult
11
00
101 2 my (@interviewers, @interviewees);
102 2 eval {
103 2 @interviewers = split /,\s?/,$interviewer;
104 };
105 2 ▶ warn "No interviewers specified" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 0 2
106 2 my ($interviewee) = $content[0] =~ /interviewee:\s?(.*)$/mi;
107 2 ▶ $interviewee ||= '';
Condition100%2/2
$interviewee ||= ""
l!l
11
MC/DC100%1/1
$interviewee ||= ""
$interviewee
Truth table100%2/2
A
A= $interviewee
Aresult
11
00
108 2 eval {
109 2 @interviewees = split /,\s?/,$interviewee;
110 };
111 2 ▶ warn "No interviewees specified" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 0 2
112 2 my %speaker;
113 2 $speaker{lc($_)} = 'class = "interviewee"' for @interviewees;
114 2 $speaker{lc($_)} = 'class = "interviewer"' for @interviewers;
115
116 2 my @first_para = split /\n/, $content[0];
117 2 $rendered .= $first_para[0] . "\n\n"; # interview title
118  
119 #remainder is metadata/ text description
120 2 $rendered .= "<p>";
121 2 $rendered .= $_ . "<br>\n" for @first_para[1 .. $#first_para];
122 2 $rendered .= "</p>\n\n";
123  
124 2 foreach my $c (@content[1 .. $#content]) {
125 6 my ($who,$time,$txt) = $c =~ /^(.*?:)\s+?(\[.*?\])\s?(.*)/ms;
126 6 my ($name) = $who =~ /(\w+):/;
127 6 ▶ $speaker{lc($name)} = '' unless exists $speaker{lc($name)};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $speaker{lc $name} 2 4 6
128 6 $rendered .= "<h2 " .$speaker{lc($name)} . ">$who</h2>\n\n<p><span class='timestamp'>$time</span>$txt</p>\n\n";
129 }
130 2 return $rendered;
131 }
132  
133 =head1 AUTHOR
134  
135 Kieren Diment, C<< <zarquon at cpan.org> >>
136  
137 =head1 BUGS
138  
139 Please report any bugs or feature requests to C<bug-text-format-interview at rt.cpan.org>, or through
140 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Format-Interview>. I will be notified, and then you'll
141 automatically be notified of progress on your bug as I make changes.
142  
143  
144  
145  
146 =head1 SUPPORT
147  
148 You can find documentation for this module with the perldoc command.
149  
150 perldoc Text::Format::Interview
151  
152  
153 You can also look for information at:
154  
155 =over 4
156  
157 =item * RT: CPAN's request tracker
158  
159 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Format-Interview>
160  
161 =item * AnnoCPAN: Annotated CPAN documentation
162  
163 L<http://annocpan.org/dist/Text-Format-Interview>
164  
165 =item * CPAN Ratings
166  
167 L<http://cpanratings.perl.org/d/Text-Format-Interview>
168  
169 =item * Search CPAN
170  
171 L<http://search.cpan.org/dist/Text-Format-Interview/>
172  
173 =item * Version Control Repository (Github)
174  
175 L<http://github.com/singingfish/Test-Format-Interview/tree/master>
176  
177 =back
178  
179 =head1 ACKNOWLEDGEMENTS
180  
181  
182 =head1 COPYRIGHT & LICENSE
183  
184 Copyright 2009 Kieren Diment, all rights reserved.
185  
186 This program is free software; you can redistribute it and/or modify it
187 under the same terms as Perl itself.
188  
189  
190 =cut
191  
192 2 1; # End of Text::Format::Interview
↑ Summary