File Coverage

blib/lib/Mail/LMLM.pm
Criterion Covered Total %
statement 46 102 45.1
branch 0 18 0.0
condition 0 2 0.0
subroutine 16 19 84.2
pod 2 2 100.0
total 64 143 44.7


line stmt bran cond sub pod time code
1             package Mail::LMLM;
2             $Mail::LMLM::VERSION = '0.6805';
3 1     1   59844 use strict;
  1         9  
  1         26  
4 1     1   4 use warnings;
  1         2  
  1         33  
5              
6 1     1   27 use 5.008;
  1         4  
7              
8 1     1   364 use Mail::LMLM::Object;
  1         2  
  1         26  
9              
10 1     1   6 use vars qw(@ISA);
  1         1  
  1         61  
11              
12             @ISA=qw(Mail::LMLM::Object);
13              
14 1     1   438 use Mail::LMLM::Render::HTML;
  1         2  
  1         28  
15              
16 1     1   371 use Mail::LMLM::Types::Ezmlm;
  1         2  
  1         35  
17 1     1   402 use Mail::LMLM::Types::Egroups;
  1         2  
  1         30  
18 1     1   370 use Mail::LMLM::Types::Listar;
  1         1  
  1         25  
19 1     1   403 use Mail::LMLM::Types::Majordomo;
  1         2  
  1         41  
20 1     1   409 use Mail::LMLM::Types::Listserv;
  1         2  
  1         25  
21 1     1   397 use Mail::LMLM::Types::Mailman;
  1         2  
  1         28  
22 1     1   402 use Mail::LMLM::Types::GoogleGroups;
  1         2  
  1         47  
23              
24 1     1   6 use vars qw(%mailing_list_classes);
  1         2  
  1         129  
25              
26             my $prefix = "Mail::LMLM::Types::";
27              
28             sub _pref
29             {
30 7     7   8 my $name = shift;
31              
32 7         19 return $prefix . $name;
33             }
34              
35             %mailing_list_classes =
36             (
37             (
38             map { $_ => _pref(ucfirst($_)) }
39             ('egroups', 'ezmlm', 'listar', 'majordomo', 'listserv', 'mailman')
40             ),
41             "google" => _pref("GoogleGroups"),
42             );
43              
44 1     1   7 use vars qw(@render_what);
  1         1  
  1         756  
45              
46             @render_what =
47             (
48             {
49             'title' => "Description",
50             'func' => "render_description",
51             'id' => "desc",
52             },
53             {
54             'title' => "Posting Guidelines",
55             'func' => "render_guidelines",
56             'id' => "post_guidelines",
57             },
58             {
59             'title' => "Subscribing to the Mailing-List",
60             'func' => "render_subscribe",
61             'id' => "subscribe",
62             },
63             {
64             'title' => "Unsubscribing from the Mailing-List",
65             'func' => "render_unsubscribe",
66             'id' => "unsubscribe",
67             },
68             {
69             'title' => "Posting Messages to the Mailing-List",
70             'func' => "render_post",
71             'id' => "posting",
72             },
73             {
74             'title' => "Contacting the Mailing-List's Owner",
75             'func' => "render_owner",
76             'id' => "owner",
77             },
78             {
79             'title' => "The Mailing-List's Homepage",
80             'func' => "render_homepage",
81             'id' => "homepage",
82             },
83             {
84             'title' => "Online Messages Archive",
85             'func' => "render_online_archive",
86             'id' => "archive",
87             },
88             );
89              
90             sub _do_nothing
91       0     {
92             }
93              
94             sub initialize
95             {
96 0     0 1   my $self = shift;
97              
98 0           my ($key, $value);
99 0           $self->{'title'} = "List of Mailing Lists";
100 0           $self->{'headline'} = "List of Mailing Lists";
101 0           $self->{'prolog'} = $self->{'epilog'} = \&_do_nothing;
102 0           $self->{'extra_classes'} = {};
103 0           while(scalar(@_))
104             {
105 0           $key = shift;
106 0           $value = shift;
107 0 0         if ($key =~ /^-?lists$/)
    0          
    0          
    0          
    0          
    0          
108             {
109 0           $self->{'lists'} = $value;
110             }
111             elsif ($key =~ /^-?title$/)
112             {
113 0           $self->{'title'} = $value;
114             }
115             elsif ($key =~ /^-?headline$/)
116             {
117 0           $self->{'headline'} = $value;
118             }
119             elsif ($key =~ /^-?extra-classes$/)
120             {
121 0           $self->{'extra_classes'} = $value;
122             }
123             elsif ($key =~ /^-?prolog$/)
124             {
125 0           $self->{'prolog'} = $value;
126             }
127             elsif ($key =~ /^-?epilog$/)
128             {
129 0           $self->{'epilog'} = $value;
130             }
131             }
132              
133 0 0         if (!exists($self->{'lists'}))
134             {
135 0           die "The lists were not defined for Mail::LMLM!";
136             }
137 0           return 0;
138             }
139              
140             sub render
141             {
142 0     0 1   my $self = shift;
143              
144 0           my ($mail_lister, $mailing_list, $o, $r, $main_o, $main_r, $filename);
145              
146 0           local(*INDEX);
147              
148 0           open INDEX, ">index.html";
149 0           $main_r = Mail::LMLM::Render::HTML->new(\*INDEX);
150              
151             $main_r->start_document(
152             $self->{'title'},
153 0           $self->{'headline'},
154             );
155              
156 0           $self->{'prolog'}->($self, $main_r);
157              
158 0           local(*O);
159              
160 0           foreach $mailing_list (@{$self->{'lists'}})
  0            
161             {
162 0           $filename = $mailing_list->{'id'}.".html";
163 0           open O, ">".$filename;
164 0           $r = Mail::LMLM::Render::HTML->new(\*O);
165              
166 0           my $class_name = $mailing_list->{'class'};
167 0   0       my $class = $mailing_list_classes{$class_name} || $self->{'extra_classes'}->{$class_name} || die "Mail::LMLM: Unknown Class \"$class_name\"";
168 0 0         if (ref($class) eq "CODE")
169             {
170 0           $mail_lister = $class->(%$mailing_list);
171             }
172             else
173             {
174 0           $mail_lister = $class->new(%$mailing_list);
175             }
176              
177             my $title = exists($mailing_list->{'title'}) ?
178             $mailing_list->{'title'} :
179 0 0         $mailing_list->{'id'};
180              
181 0           $r->start_document($title, $title);
182              
183 0           foreach my $what (@render_what)
184             {
185 0           my $func = $what->{'func'};
186 0           $r->start_section($what->{'title'}, +{'id' => $what->{'id'}});
187 0           $mail_lister->$func($r);
188 0           $r->end_section();
189             }
190              
191 0           $main_r->start_section($title, {'title_url' => $filename});
192 0           $mail_lister->render_description($main_r);
193 0           $main_r->end_section();
194              
195 0           $r->end_document();
196              
197 0           close(O);
198             }
199              
200 0           $self->{'epilog'}->($self, $main_r);
201              
202 0           $main_r->end_document();
203 0           close(INDEX);
204              
205 0           local(*STYLE);
206 0           open STYLE, ">style.css";
207 0           print STYLE <<"EOF";
208             a:hover { background-color : LightGreen }
209             div.indent { margin-left : 3em }
210             EOF
211              
212 0           close(STYLE);
213             }
214              
215             #### Documentation
216              
217             __END__