lib/App/Followme/CreateRss.pm

filter: Statementstmt 100% 71 / 71 Branchbran n/a Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 14 / 14 Podpod 40.0% 2 / 5 totaltotal 94.6% 88 / 93 CC 3 SCAR 2.2
CC
3
Cov
99%
setup
2.0
build_rss
2.0
BEGIN
1.0
CRAP 1.3
« lib/App/Followme/JpegData.pm ↑ Summary lib/App/Followme/BinaryData.pm »
1 package App::Followme::CreateRss;
2  
3 1 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use lib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base qw(App::Followme::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use File::Spec::Functions qw(catfile splitdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use App::Followme::FIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use App::Followme::NestedText;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = "2.03";
18  
19 #----------------------------------------------------------------------
20 # Read the default parameter values
21  
22 4 ▶sub parameters {
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
23 4 my ($pkg) = @_;
24  
25 return (
26 4 rss_extension => 'rss',
27 data_pkg => 'App::Followme::WebData',
28 );
29 }
30  
31 #----------------------------------------------------------------------
32 # Write an rss file for the web pages in a directory
33  
34 1 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
35 1 my ($self, $folder) = @_;
36  
37 1 my %rss = $self->build_rss($folder);
38  
39 1 my @path = splitdir($folder);
40 1 my $filename = pop(@path) . '.' . $self->{rss_extension};
41 1 $filename = catfile($folder, $filename);
42  
43 1 nt_write_almost_xml_file($filename, %rss);
44  
45 1 return;
46 }
47  
48 #----------------------------------------------------------------------
49 # Return an rss file of the newest web pages in a directory
50  
51 1 ▶sub build_rss {
Subroutine build_rss: called CC=2 SCAR=6.9
Pod undocumented
52 1 my ($self, $folder) = @_;
53  
54 1 my $index_file = $self->to_file($folder);
55 1 my $info = $self->file_info($index_file);
56 1 my %channel = %$info;
57 1 delete $channel{guid};
58  
59 1 my @items;
60 1 my $files = $self->{data}->build('top_files_by_mdate_reversed',
61 $index_file);
62  
63 1 foreach my $file (@$files) {
64 3 push(@items, $self->file_info($file));
65 }
66 1 $channel{item} = \@items;
67  
68 1 my $rss_tag = 'rss version="2.0"';
69 1 my %rss = ($rss_tag => {channel => \%channel});
70  
71 1 return %rss;
72 }
73  
74 #----------------------------------------------------------------------
75 # Return the pertinent information about a file for the rss file
76  
77 4 ▶sub file_info {
Subroutine file_info: called CC=1 SCAR=0.0
Pod undocumented
78 4 my ($self, $file) = @_;
79 4 my $info = {};
80  
81 # build returns a reference, so must dereference
82  
83 4 $info->{title} = ${$self->{data}->build('title', $file)};
84 4 $info->{author} = ${$self->{data}->build('author', $file)};
85 4 $info->{description} = ${$self->{data}->build('description', $file)};
86 4 $info->{pubDate} = ${$self->{data}->build('date', $file)};
87 4 $info->{link} = ${$self->{data}->build('remote_url', $file)};
88  
89 4 my $guid = encode_base64($info->{link});
90 4 $guid =~ s/=*\n$//;
91 4 $info->{guid} = $guid;
92  
93 4 return $info;
94 }
95  
96 #----------------------------------------------------------------------
97 # Set exclude_index to true and set default date format
98  
99 1 ▶sub setup {
Subroutine setup: called CC=2 SCAR=7.0
Pod documented
100 1 my ($self) = @_;
101  
102 1 $self->{extension} = $self->{web_extension};
103 1 ▶ $self->{data}{date_format} ||= 'Day, dd Mon yyyy';
Condition50%1/2
$self->{"data"}{"date_format"} ||= "Day, dd Mon yyyy"
l!l
10
MC/DC0%0/1
$self->{"data"}{"date_format"} ||= "Day, dd Mon yyyy"
$self->{"data"}{"date_format"}
Truth table50%1/2
A
A= $self->{"data"}{"date_format"}
Aresult
11
00
104 1 $self->{data}{exclude_index} = 1;
105 1 return;
106 }
107  
108 1 1;
109 __END__
« lib/App/Followme/JpegData.pm ↑ Summary lib/App/Followme/BinaryData.pm »