| 1 | package HTML::Latemp::News; | ||||||||||
| 2 | $HTML::Latemp::News::VERSION = '0.2.1'; | ||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | package HTML::Latemp::News::Base; | ||||||||||
| 10 | $HTML::Latemp::News::Base::VERSION = '0.2.1'; | ||||||||||
| 11 | 2 | ▶ | use CGI (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | sub new | ||||||||||
| 14 | { | ||||||||||
| 15 | 0 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | 0 | my $self = {}; | |||||||||
| 17 | 0 | bless $self, $class; | |||||||||
| 18 | 0 | $self->initialize(@_); | |||||||||
| 19 | 0 | return $self; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | package HTML::Latemp::News::Item; | ||||||||||
| 23 | $HTML::Latemp::News::Item::VERSION = '0.2.1'; | ||||||||||
| 24 | our @ISA = (qw(HTML::Latemp::News::Base)); | ||||||||||
| 25 | |||||||||||
| 26 | sub author | ||||||||||
| 27 | { | ||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
author: not called CC=2 SCAR=17.9
| |||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | { | ||||||||||
| 32 | 0 | $self->{author} = shift; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | return $self->{author}; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub category | ||||||||||
| 39 | { | ||||||||||
| 40 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
category: not called CC=2 SCAR=17.9
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | { | ||||||||||
| 44 | 0 | $self->{category} = shift; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | return $self->{category}; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub date | ||||||||||
| 51 | { | ||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
date: not called CC=2 SCAR=17.9
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | { | ||||||||||
| 56 | 0 | $self->{date} = shift; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | return $self->{date}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | sub description | ||||||||||
| 63 | { | ||||||||||
| 64 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
description: not called CC=2 SCAR=17.9
| |||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | { | ||||||||||
| 68 | 0 | $self->{description} = shift; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | return $self->{description}; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub id | ||||||||||
| 75 | { | ||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | { | ||||||||||
| 80 | 0 | $self->{id} = shift; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 0 | return $self->{id}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub index | ||||||||||
| 87 | { | ||||||||||
| 88 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
index: not called CC=2 SCAR=17.9
| |||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | { | ||||||||||
| 92 | 0 | $self->{index} = shift; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | return $self->{index}; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | sub text | ||||||||||
| 99 | { | ||||||||||
| 100 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
text: not called CC=2 SCAR=17.9
| |||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | { | ||||||||||
| 104 | 0 | $self->{text} = shift; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | return $self->{text}; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | sub title | ||||||||||
| 111 | { | ||||||||||
| 112 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
title: not called CC=2 SCAR=17.9
| |||||||||||
| 113 | |||||||||||
| 114 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | { | ||||||||||
| 116 | 0 | $self->{title} = shift; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | return $self->{title}; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | sub initialize | ||||||||||
| 123 | { | ||||||||||
| 124 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
initialize: not called CC=3 SCAR=24.8
| |||||||||||
| 125 | |||||||||||
| 126 | 0 | my (%args) = (@_); | |||||||||
| 127 | |||||||||||
| 128 | 0 | foreach my $k ( keys(%args) ) | |||||||||
| 129 | { | ||||||||||
| 130 | 0 | ▶ | if ( !$self->can($k) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | { | ||||||||||
| 132 | 0 | die "Unknown property for HTML::Latemp::News::Item - \"$k\"!"; | |||||||||
| 133 | } | ||||||||||
| 134 | 0 | $self->can($k)->( $self, $args{$k} ); | |||||||||
| 135 | } | ||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | package HTML::Latemp::News; | ||||||||||
| 139 | |||||||||||
| 140 | our @ISA = (qw(HTML::Latemp::News::Base)); | ||||||||||
| 141 | |||||||||||
| 142 | sub copyright | ||||||||||
| 143 | { | ||||||||||
| 144 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
copyright: not called CC=2 SCAR=17.9
| |||||||||||
| 145 | |||||||||||
| 146 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 147 | { | ||||||||||
| 148 | 0 | $self->{copyright} = shift; | |||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | 0 | return $self->{copyright}; | |||||||||
| 152 | } | ||||||||||
| 153 | |||||||||||
| 154 | sub description | ||||||||||
| 155 | { | ||||||||||
| 156 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
description: not called CC=2 SCAR=17.9
| |||||||||||
| 157 | |||||||||||
| 158 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | { | ||||||||||
| 160 | 0 | $self->{description} = shift; | |||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 0 | return $self->{description}; | |||||||||
| 164 | } | ||||||||||
| 165 | |||||||||||
| 166 | sub docs | ||||||||||
| 167 | { | ||||||||||
| 168 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
docs: not called CC=2 SCAR=17.9
| |||||||||||
| 169 | |||||||||||
| 170 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 171 | { | ||||||||||
| 172 | 0 | $self->{docs} = shift; | |||||||||
| 173 | } | ||||||||||
| 174 | |||||||||||
| 175 | 0 | return $self->{docs}; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | sub generator | ||||||||||
| 179 | { | ||||||||||
| 180 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
generator: not called CC=2 SCAR=17.9
| |||||||||||
| 181 | |||||||||||
| 182 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 183 | { | ||||||||||
| 184 | 0 | $self->{generator} = shift; | |||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | 0 | return $self->{generator}; | |||||||||
| 188 | } | ||||||||||
| 189 | |||||||||||
| 190 | sub items | ||||||||||
| 191 | { | ||||||||||
| 192 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
items: not called CC=2 SCAR=17.9
| |||||||||||
| 193 | |||||||||||
| 194 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 195 | { | ||||||||||
| 196 | 0 | $self->{items} = shift; | |||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | 0 | return $self->{items}; | |||||||||
| 200 | } | ||||||||||
| 201 | |||||||||||
| 202 | sub language | ||||||||||
| 203 | { | ||||||||||
| 204 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
language: not called CC=2 SCAR=17.9
| |||||||||||
| 205 | |||||||||||
| 206 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 207 | { | ||||||||||
| 208 | 0 | $self->{language} = shift; | |||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | 0 | return $self->{language}; | |||||||||
| 212 | } | ||||||||||
| 213 | |||||||||||
| 214 | sub link | ||||||||||
| 215 | { | ||||||||||
| 216 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
link: not called CC=2 SCAR=17.9
| |||||||||||
| 217 | |||||||||||
| 218 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 219 | { | ||||||||||
| 220 | 0 | $self->{link} = shift; | |||||||||
| 221 | } | ||||||||||
| 222 | |||||||||||
| 223 | 0 | return $self->{link}; | |||||||||
| 224 | } | ||||||||||
| 225 | |||||||||||
| 226 | sub managing_editor | ||||||||||
| 227 | { | ||||||||||
| 228 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
managing_editor: not called CC=2 SCAR=17.9
| |||||||||||
| 229 | |||||||||||
| 230 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 231 | { | ||||||||||
| 232 | 0 | $self->{managing_editor} = shift; | |||||||||
| 233 | } | ||||||||||
| 234 | |||||||||||
| 235 | 0 | return $self->{managing_editor}; | |||||||||
| 236 | } | ||||||||||
| 237 | |||||||||||
| 238 | sub lastBuildDate | ||||||||||
| 239 | { | ||||||||||
| 240 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
lastBuildDate: not called CC=2 SCAR=17.9
| |||||||||||
| 241 | |||||||||||
| 242 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 243 | { | ||||||||||
| 244 | 0 | $self->{lastBuildDate} = shift; | |||||||||
| 245 | } | ||||||||||
| 246 | |||||||||||
| 247 | 0 | return $self->{lastBuildDate}; | |||||||||
| 248 | } | ||||||||||
| 249 | |||||||||||
| 250 | sub pubDate | ||||||||||
| 251 | { | ||||||||||
| 252 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
pubDate: not called CC=2 SCAR=17.9
| |||||||||||
| 253 | |||||||||||
| 254 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 255 | { | ||||||||||
| 256 | 0 | $self->{pubDate} = shift; | |||||||||
| 257 | } | ||||||||||
| 258 | |||||||||||
| 259 | 0 | return $self->{pubDate}; | |||||||||
| 260 | } | ||||||||||
| 261 | |||||||||||
| 262 | sub rating | ||||||||||
| 263 | { | ||||||||||
| 264 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
rating: not called CC=2 SCAR=17.9
| |||||||||||
| 265 | |||||||||||
| 266 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 267 | { | ||||||||||
| 268 | 0 | $self->{rating} = shift; | |||||||||
| 269 | } | ||||||||||
| 270 | |||||||||||
| 271 | 0 | return $self->{rating}; | |||||||||
| 272 | } | ||||||||||
| 273 | |||||||||||
| 274 | sub title | ||||||||||
| 275 | { | ||||||||||
| 276 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
title: not called CC=2 SCAR=17.9
| |||||||||||
| 277 | |||||||||||
| 278 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 279 | { | ||||||||||
| 280 | 0 | $self->{title} = shift; | |||||||||
| 281 | } | ||||||||||
| 282 | |||||||||||
| 283 | 0 | return $self->{title}; | |||||||||
| 284 | } | ||||||||||
| 285 | |||||||||||
| 286 | sub ttl | ||||||||||
| 287 | { | ||||||||||
| 288 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
ttl: not called CC=2 SCAR=17.9
| |||||||||||
| 289 | |||||||||||
| 290 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 291 | { | ||||||||||
| 292 | 0 | $self->{ttl} = shift; | |||||||||
| 293 | } | ||||||||||
| 294 | |||||||||||
| 295 | 0 | return $self->{ttl}; | |||||||||
| 296 | } | ||||||||||
| 297 | |||||||||||
| 298 | sub webmaster | ||||||||||
| 299 | { | ||||||||||
| 300 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
webmaster: not called CC=2 SCAR=17.9
| |||||||||||
| 301 | |||||||||||
| 302 | 0 | ▶ | if (@_) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 303 | { | ||||||||||
| 304 | 0 | $self->{webmaster} = shift; | |||||||||
| 305 | } | ||||||||||
| 306 | |||||||||||
| 307 | 0 | return $self->{webmaster}; | |||||||||
| 308 | } | ||||||||||
| 309 | 2 | ▶ | use XML::RSS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||||||||||
| 310 | |||||||||||
| 311 | sub input_items | ||||||||||
| 312 | { | ||||||||||
| 313 | my $self = shift; | ||||||||||
| 314 | |||||||||||
| 315 | my $items = shift; | ||||||||||
| 316 | |||||||||||
| 317 | return [ map { $self->input_single_item( $_, $items->[$_] ) } | ||||||||||
| 318 | ( 0 .. $#$items ) ]; | ||||||||||
| 319 | } | ||||||||||
| 320 | |||||||||||
| 321 | sub input_single_item | ||||||||||
| 322 | { | ||||||||||
| 323 | my $self = shift; | ||||||||||
| 324 | my ( $index, $inputted_item ) = (@_); | ||||||||||
| 325 | |||||||||||
| 326 | return HTML::Latemp::News::Item->new( %$inputted_item, 'index' => $index, ); | ||||||||||
| 327 | } | ||||||||||
| 328 | |||||||||||
| 329 | sub initialize | ||||||||||
| 330 | { | ||||||||||
| 331 | my $self = shift; | ||||||||||
| 332 | |||||||||||
| 333 | my %args = (@_); | ||||||||||
| 334 | |||||||||||
| 335 | my $items = $args{'news_items'}; | ||||||||||
| 336 | |||||||||||
| 337 | $self->items( $self->input_items($items) ); | ||||||||||
| 338 | |||||||||||
| 339 | $self->title( $args{'title'} ); | ||||||||||
| 340 | $self->link( $args{'link'} ); | ||||||||||
| 341 | $self->language( $args{'language'} ); | ||||||||||
| 342 | $self->rating( $args{'rating'} | ||||||||||
| 343 | || '(PICS-1.1 "http://www.classify.org/safesurf/" 1 r (SS~~000 1))' | ||||||||||
| 344 | ); | ||||||||||
| 345 | $self->copyright( $args{'copyright'} || "" ); | ||||||||||
| 346 | $self->docs( $args{'docs'} || "http://blogs.law.harvard.edu/tech/rss" ); | ||||||||||
| 347 | $self->ttl( $args{'ttl'} || "360" ); | ||||||||||
| 348 | $self->generator( $args{'generator'} || "Perl and XML::RSS" ); | ||||||||||
| 349 | $self->webmaster( $args{'webmaster'} ); | ||||||||||
| 350 | $self->managing_editor( $args{'managing_editor'} || $self->webmaster() ); | ||||||||||
| 351 | $self->description( $args{'description'} ); | ||||||||||
| 352 | |||||||||||
| 353 | if ( defined( my $date = delete $args{lastBuildDate} ) ) | ||||||||||
| 354 | { | ||||||||||
| 355 | $self->lastBuildDate($date); | ||||||||||
| 356 | } | ||||||||||
| 357 | if ( defined( my $date = delete $args{pubDate} ) ) | ||||||||||
| 358 | { | ||||||||||
| 359 | $self->pubDate($date); | ||||||||||
| 360 | } | ||||||||||
| 361 | |||||||||||
| 362 | return 0; | ||||||||||
| 363 | } | ||||||||||
| 364 | |||||||||||
| 365 | |||||||||||
| 366 | sub add_item_to_rss_feed | ||||||||||
| 367 | { | ||||||||||
| 368 | my $self = shift; | ||||||||||
| 369 | my %args = (@_); | ||||||||||
| 370 | |||||||||||
| 371 | my $item = $args{'item'}; | ||||||||||
| 372 | my $rss_feed = $args{'feed'}; | ||||||||||
| 373 | |||||||||||
| 374 | my $item_url = $self->get_item_url($item); | ||||||||||
| 375 | |||||||||||
| 376 | $rss_feed->add_item( | ||||||||||
| 377 | 'title' => $item->title(), | ||||||||||
| 378 | 'link' => $item_url, | ||||||||||
| 379 | 'permaLink' => $item_url, | ||||||||||
| 380 | 'enclosure' => { 'url' => $item_url, }, | ||||||||||
| 381 | 'description' => $item->description(), | ||||||||||
| 382 | 'author' => $item->author(), | ||||||||||
| 383 | 'pubDate' => $item->date(), | ||||||||||
| 384 | 'category' => $item->category(), | ||||||||||
| 385 | ); | ||||||||||
| 386 | } | ||||||||||
| 387 | |||||||||||
| 388 | sub get_item_url | ||||||||||
| 389 | { | ||||||||||
| 390 | my $self = shift; | ||||||||||
| 391 | my $item = shift; | ||||||||||
| 392 | return $self->link() . $self->get_item_rel_url($item); | ||||||||||
| 393 | } | ||||||||||
| 394 | |||||||||||
| 395 | sub get_item_rel_url | ||||||||||
| 396 | { | ||||||||||
| 397 | my $self = shift; | ||||||||||
| 398 | my $item = shift; | ||||||||||
| 399 | return "news/" . $item->id() . "/"; | ||||||||||
| 400 | } | ||||||||||
| 401 | |||||||||||
| 402 | sub get_items_to_include | ||||||||||
| 403 | { | ||||||||||
| 404 | my $self = shift; | ||||||||||
| 405 | my $args = shift; | ||||||||||
| 406 | |||||||||||
| 407 | my $num_items_to_include = $args->{'num_items'} || 10; | ||||||||||
| 408 | |||||||||||
| 409 | my $items = $self->items(); | ||||||||||
| 410 | |||||||||||
| 411 | if ( @$items < $num_items_to_include ) | ||||||||||
| 412 | { | ||||||||||
| 413 | $num_items_to_include = scalar(@$items); | ||||||||||
| 414 | } | ||||||||||
| 415 | |||||||||||
| 416 | return [ @$items[ ( -$num_items_to_include ) .. (-1) ] ]; | ||||||||||
| 417 | } | ||||||||||
| 418 | |||||||||||
| 419 | sub generate_rss_feed | ||||||||||
| 420 | { | ||||||||||
| 421 | my $self = shift; | ||||||||||
| 422 | |||||||||||
| 423 | my %args = (@_); | ||||||||||
| 424 | |||||||||||
| 425 | my $rss_feed = XML::RSS->new( 'version' => "2.0" ); | ||||||||||
| 426 | $rss_feed->channel( | ||||||||||
| 427 | 'title' => $self->title(), | ||||||||||
| 428 | 'link' => $self->link(), | ||||||||||
| 429 | 'language' => $self->language(), | ||||||||||
| 430 | 'description' => $self->description(), | ||||||||||
| 431 | 'rating' => $self->rating(), | ||||||||||
| 432 | 'copyright' => $self->copyright(), | ||||||||||
| 433 | 'pubDate' => ( $self->pubDate // ( scalar( localtime() ) ) ), | ||||||||||
| 434 | 'lastBuildDate' => | ||||||||||
| 435 | ( $self->lastBuildDate // ( scalar( localtime() ) ) ), | ||||||||||
| 436 | 'docs' => $self->docs(), | ||||||||||
| 437 | 'ttl' => $self->ttl(), | ||||||||||
| 438 | 'generator' => $self->generator(), | ||||||||||
| 439 | 'managingEditor' => $self->managing_editor(), | ||||||||||
| 440 | 'webMaster' => $self->webmaster(), | ||||||||||
| 441 | ); | ||||||||||
| 442 | |||||||||||
| 443 | foreach my $single_item ( @{ $self->get_items_to_include( \%args ) } ) | ||||||||||
| 444 | { | ||||||||||
| 445 | $self->add_item_to_rss_feed( | ||||||||||
| 446 | 'item' => $single_item, | ||||||||||
| 447 | 'feed' => $rss_feed, | ||||||||||
| 448 | ); | ||||||||||
| 449 | } | ||||||||||
| 450 | |||||||||||
| 451 | my $filename = $args{'output_filename'} || "rss.xml"; | ||||||||||
| 452 | |||||||||||
| 453 | $rss_feed->save($filename); | ||||||||||
| 454 | } | ||||||||||
| 455 | |||||||||||
| 456 | |||||||||||
| 457 | sub get_navmenu_items | ||||||||||
| 458 | { | ||||||||||
| 459 | my $self = shift; | ||||||||||
| 460 | my %args = (@_); | ||||||||||
| 461 | |||||||||||
| 462 | my @ret; | ||||||||||
| 463 | |||||||||||
| 464 | foreach my $single_item ( | ||||||||||
| 465 | reverse( @{ $self->get_items_to_include( \%args ) } ) ) | ||||||||||
| 466 | { | ||||||||||
| 467 | push @ret, | ||||||||||
| 468 | { | ||||||||||
| 469 | 'text' => $single_item->title(), | ||||||||||
| 470 | 'url' => $self->get_item_rel_url($single_item), | ||||||||||
| 471 | }; | ||||||||||
| 472 | } | ||||||||||
| 473 | return \@ret; | ||||||||||
| 474 | } | ||||||||||
| 475 | |||||||||||
| 476 | |||||||||||
| 477 | sub format_news_page_item | ||||||||||
| 478 | { | ||||||||||
| 479 | my $self = shift; | ||||||||||
| 480 | my (%args) = (@_); | ||||||||||
| 481 | |||||||||||
| 482 | my $item = $args{'item'}; | ||||||||||
| 483 | my $base_url = $args{'base_url'}; | ||||||||||
| 484 | |||||||||||
| 485 | return | ||||||||||
| 486 | "<h3><a href=\"$base_url" | ||||||||||
| 487 | . $item->id() . "/\">" | ||||||||||
| 488 | . CGI::escapeHTML( $item->title() ) | ||||||||||
| 489 | . "</a></h3>\n" . "<p>\n" | ||||||||||
| 490 | . $item->description() | ||||||||||
| 491 | . "\n</p>\n"; | ||||||||||
| 492 | } | ||||||||||
| 493 | |||||||||||
| 494 | sub get_news_page_entries | ||||||||||
| 495 | { | ||||||||||
| 496 | my $self = shift; | ||||||||||
| 497 | my %args = (@_); | ||||||||||
| 498 | |||||||||||
| 499 | my $html = ""; | ||||||||||
| 500 | |||||||||||
| 501 | my $base_url = exists( $args{'base_url'} ) ? $args{'base_url'} : ""; | ||||||||||
| 502 | |||||||||||
| 503 | foreach my $single_item ( | ||||||||||
| 504 | reverse( @{ $self->get_items_to_include( \%args ) } ) ) | ||||||||||
| 505 | { | ||||||||||
| 506 | $html .= $self->format_news_page_item( | ||||||||||
| 507 | 'item' => $single_item, | ||||||||||
| 508 | 'base_url' => $base_url, | ||||||||||
| 509 | ); | ||||||||||
| 510 | } | ||||||||||
| 511 | return $html; | ||||||||||
| 512 | } | ||||||||||
| 513 | |||||||||||
| 514 | |||||||||||
| 515 | sub get_news_box_contents | ||||||||||
| 516 | { | ||||||||||
| 517 | my $self = shift; | ||||||||||
| 518 | my (%args) = (@_); | ||||||||||
| 519 | |||||||||||
| 520 | my $html = ""; | ||||||||||
| 521 | foreach my $item ( reverse( @{ $self->get_items_to_include( \%args ) } ) ) | ||||||||||
| 522 | { | ||||||||||
| 523 | $html .= | ||||||||||
| 524 | "<li><a href=\"" | ||||||||||
| 525 | . $self->get_item_rel_url($item) . "\">" | ||||||||||
| 526 | . CGI::escapeHTML( $item->title() ) | ||||||||||
| 527 | . "</a></li>\n"; | ||||||||||
| 528 | } | ||||||||||
| 529 | return $html; | ||||||||||
| 530 | } | ||||||||||
| 531 | |||||||||||
| 532 | sub get_news_box | ||||||||||
| 533 | { | ||||||||||
| 534 | my $self = shift; | ||||||||||
| 535 | |||||||||||
| 536 | my $html = ""; | ||||||||||
| 537 | |||||||||||
| 538 | $html .= qq{<div class="news">\n}; | ||||||||||
| 539 | $html .= qq{<h3>News</h3>\n}; | ||||||||||
| 540 | $html .= qq{<ul>\n}; | ||||||||||
| 541 | $html .= $self->get_news_box_contents(@_); | ||||||||||
| 542 | $html .= qq{<li><a href="./news/">More…</a></li>}; | ||||||||||
| 543 | $html .= qq{</ul>\n}; | ||||||||||
| 544 | $html .= qq{</div>\n}; | ||||||||||
| 545 | return $html; | ||||||||||
| 546 | } | ||||||||||
| 547 | |||||||||||
| 548 | |||||||||||
| 549 | 1; | ||||||||||
| 550 | |||||||||||
| 551 | __END__ | ||||||||||
| 552 | |||||||||||
| 553 | =pod | ||||||||||
| 554 | |||||||||||
| 555 | =encoding UTF-8 | ||||||||||
| 556 | |||||||||||
| 557 | =head1 NAME | ||||||||||
| 558 | |||||||||||
| 559 | HTML::Latemp::News - News Maintenance Module for Latemp (and possibly other | ||||||||||
| 560 | web frameworks) | ||||||||||
| 561 | |||||||||||
| 562 | =head1 VERSION | ||||||||||
| 563 | |||||||||||
| 564 | version 0.2.1 | ||||||||||
| 565 | |||||||||||
| 566 | =head1 SYNOPSIS | ||||||||||
| 567 | |||||||||||
| 568 | #!/usr/bin/perl | ||||||||||
| 569 | |||||||||||
| 570 | use strict; | ||||||||||
| 571 | use warnings; | ||||||||||
| 572 | |||||||||||
| 573 | use MyManageNews; | ||||||||||
| 574 | |||||||||||
| 575 | my @news_items = | ||||||||||
| 576 | ( | ||||||||||
| 577 | . | ||||||||||
| 578 | . | ||||||||||
| 579 | . | ||||||||||
| 580 | { | ||||||||||
| 581 | 'title' => "Changes of 18-April-2005", | ||||||||||
| 582 | 'id' => "changes-2005-04-18", | ||||||||||
| 583 | 'description' => q{Around 18 April, 2005, Jane's Site has seen a | ||||||||||
| 584 | lot of changes. Click the link for details on them.}, | ||||||||||
| 585 | 'date' => "2005-04-18", | ||||||||||
| 586 | 'author' => "Jane Smith", | ||||||||||
| 587 | 'category' => "Jane's Site", | ||||||||||
| 588 | }, | ||||||||||
| 589 | . | ||||||||||
| 590 | . | ||||||||||
| 591 | . | ||||||||||
| 592 | ); | ||||||||||
| 593 | |||||||||||
| 594 | my $news_manager = | ||||||||||
| 595 | HTML::Latemp::News->new( | ||||||||||
| 596 | 'news_items' => \@news_items, | ||||||||||
| 597 | 'title' => "Better SCM News", | ||||||||||
| 598 | 'link' => "http://janes-site.tld/", | ||||||||||
| 599 | 'language' => "en-US", | ||||||||||
| 600 | 'copyright' => "Copyright by Jane Smith, (c) 2005", | ||||||||||
| 601 | 'webmaster' => "Jane Smith <jane@janes-site.tld>", | ||||||||||
| 602 | 'managing_editor' => "Jane Smith <jane@janes-site.tld>", | ||||||||||
| 603 | 'description' => "News of Jane's Site - a personal site of " . | ||||||||||
| 604 | "Jane Smith", | ||||||||||
| 605 | ); | ||||||||||
| 606 | |||||||||||
| 607 | $news_manager->generate_rss_feed( | ||||||||||
| 608 | 'output_filename' => "dest/rss.xml" | ||||||||||
| 609 | ); | ||||||||||
| 610 | |||||||||||
| 611 | 1; | ||||||||||
| 612 | |||||||||||
| 613 | =head1 DESCRIPTION | ||||||||||
| 614 | |||||||||||
| 615 | This is a module that maintains news item for a web-site. It can generate | ||||||||||
| 616 | an RSS feed, as well as a news page, and an HTML newsbox, all from the same | ||||||||||
| 617 | data. | ||||||||||
| 618 | |||||||||||
| 619 | =head1 VERSION | ||||||||||
| 620 | |||||||||||
| 621 | version 0.2.1 | ||||||||||
| 622 | |||||||||||
| 623 | =head1 FUNCTION | ||||||||||
| 624 | |||||||||||
| 625 | =head2 HTML::Latemp::News->new(...) | ||||||||||
| 626 | |||||||||||
| 627 | This is the constructor for the news manager. It accepts the following named | ||||||||||
| 628 | parameters: | ||||||||||
| 629 | |||||||||||
| 630 | =over 8 | ||||||||||
| 631 | |||||||||||
| 632 | =item 'news_items' | ||||||||||
| 633 | |||||||||||
| 634 | This is a reference to a list of news_items. See below. | ||||||||||
| 635 | |||||||||||
| 636 | =item 'title' | ||||||||||
| 637 | |||||||||||
| 638 | The title of the RSS feed. | ||||||||||
| 639 | |||||||||||
| 640 | =item 'link' | ||||||||||
| 641 | |||||||||||
| 642 | The link to the homepage of the site. | ||||||||||
| 643 | |||||||||||
| 644 | =item 'language' | ||||||||||
| 645 | |||||||||||
| 646 | The language of the text. | ||||||||||
| 647 | |||||||||||
| 648 | =item 'copyright' | ||||||||||
| 649 | |||||||||||
| 650 | The copyright notice of the text. | ||||||||||
| 651 | |||||||||||
| 652 | =item 'webmaster' | ||||||||||
| 653 | |||||||||||
| 654 | The Webmaster. | ||||||||||
| 655 | |||||||||||
| 656 | =item 'managing_editor' | ||||||||||
| 657 | |||||||||||
| 658 | The managing editor. | ||||||||||
| 659 | |||||||||||
| 660 | =item 'description' | ||||||||||
| 661 | |||||||||||
| 662 | A description of the news feed as will be put in the RSS feed. | ||||||||||
| 663 | |||||||||||
| 664 | =back | ||||||||||
| 665 | |||||||||||
| 666 | =head3 Format of the news_items | ||||||||||
| 667 | |||||||||||
| 668 | The news_items is a reference to an array, of which each element is a hash | ||||||||||
| 669 | reference. The hash may contain the following keys: | ||||||||||
| 670 | |||||||||||
| 671 | =over 8 | ||||||||||
| 672 | |||||||||||
| 673 | =item 'title' | ||||||||||
| 674 | |||||||||||
| 675 | The title of the item. | ||||||||||
| 676 | |||||||||||
| 677 | =item 'id' | ||||||||||
| 678 | |||||||||||
| 679 | The ID of the item. This will also be used to calculate URLs. | ||||||||||
| 680 | |||||||||||
| 681 | =item 'description' | ||||||||||
| 682 | |||||||||||
| 683 | A text description explaining what the item is all about. | ||||||||||
| 684 | |||||||||||
| 685 | =item 'author' | ||||||||||
| 686 | |||||||||||
| 687 | The author of the item. | ||||||||||
| 688 | |||||||||||
| 689 | =item 'date' | ||||||||||
| 690 | |||||||||||
| 691 | A string representing the daet. | ||||||||||
| 692 | |||||||||||
| 693 | =item 'category' | ||||||||||
| 694 | |||||||||||
| 695 | The cateogry of the item. | ||||||||||
| 696 | |||||||||||
| 697 | =back | ||||||||||
| 698 | |||||||||||
| 699 | =head2 $news_manager->generate_rss_feed('output_filename' => "rss.xml") | ||||||||||
| 700 | |||||||||||
| 701 | This generates an RSS feed. It accepts two named arguments. | ||||||||||
| 702 | C<'output_filename'> is the name of the RSS file to write to. C<'num_items'> | ||||||||||
| 703 | is the number of items to include, which defaults to 10. | ||||||||||
| 704 | |||||||||||
| 705 | =head2 $news_manager->get_navmenu_items('num_items' => 5) | ||||||||||
| 706 | |||||||||||
| 707 | This generates navigation menu items for input to the navigation menu of | ||||||||||
| 708 | L<HTML::Widgets::NavMenu>. It accepts a named argument C<'num_items'> which | ||||||||||
| 709 | defaults to 10. | ||||||||||
| 710 | |||||||||||
| 711 | =head2 $news_manager->get_news_page_entries('num_items' => 5, 'base_url' => "news/") | ||||||||||
| 712 | |||||||||||
| 713 | This generates HTML for the news page. 'base_url' points to a URL to be | ||||||||||
| 714 | appended to each item's ID. | ||||||||||
| 715 | |||||||||||
| 716 | =head2 $news_manager->get_news_box('num_items' => 5) | ||||||||||
| 717 | |||||||||||
| 718 | This generates an HTML news box with the recent headlines. | ||||||||||
| 719 | |||||||||||
| 720 | =head1 AUTHOR | ||||||||||
| 721 | |||||||||||
| 722 | Shlomi Fish, L<http://www.shlomifish.org/> . | ||||||||||
| 723 | |||||||||||
| 724 | =head1 BUGS | ||||||||||
| 725 | |||||||||||
| 726 | Please report any bugs or feature requests to | ||||||||||
| 727 | C<bug-html-latemp-news@rt.cpan.org>, or through the web interface at | ||||||||||
| 728 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Latemp-News>. | ||||||||||
| 729 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 730 | your bug as I make changes. | ||||||||||
| 731 | |||||||||||
| 732 | =head1 SEE ALSO | ||||||||||
| 733 | |||||||||||
| 734 | L<XML::RSS>, L<HTML::Widgets::NavMenu>. | ||||||||||
| 735 | |||||||||||
| 736 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 737 | |||||||||||
| 738 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 739 | |||||||||||
| 740 | Copyright 2005 Shlomi Fish, All Rights Reserved. | ||||||||||
| 741 | |||||||||||
| 742 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 743 | under the terms of the MIT X11 license. | ||||||||||
| 744 | |||||||||||
| 745 | =head1 AUTHOR | ||||||||||
| 746 | |||||||||||
| 747 | Shlomi Fish <shlomif@cpan.org> | ||||||||||
| 748 | |||||||||||
| 749 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 750 | |||||||||||
| 751 | This software is Copyright (c) 2005 by Shlomi Fish. | ||||||||||
| 752 | |||||||||||
| 753 | This is free software, licensed under: | ||||||||||
| 754 | |||||||||||
| 755 | The MIT (X11) License | ||||||||||
| 756 | |||||||||||
| 757 | =head1 BUGS | ||||||||||
| 758 | |||||||||||
| 759 | Please report any bugs or feature requests on the bugtracker website | ||||||||||
| 760 | L<https://github.com/shlomif/html-latemp-news/issues> | ||||||||||
| 761 | |||||||||||
| 762 | When submitting a bug or request, please include a test-file or a | ||||||||||
| 763 | patch to an existing test-file that illustrates the bug or desired | ||||||||||
| 764 | feature. | ||||||||||
| 765 | |||||||||||
| 766 | =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan | ||||||||||
| 767 | |||||||||||
| 768 | =head1 SUPPORT | ||||||||||
| 769 | |||||||||||
| 770 | =head2 Perldoc | ||||||||||
| 771 | |||||||||||
| 772 | You can find documentation for this module with the perldoc command. | ||||||||||
| 773 | |||||||||||
| 774 | perldoc HTML::Latemp::News | ||||||||||
| 775 | |||||||||||
| 776 | =head2 Websites | ||||||||||
| 777 | |||||||||||
| 778 | The following websites have more information about this module, and may be of help to you. As always, | ||||||||||
| 779 | in addition to those websites please use your favorite search engine to discover more resources. | ||||||||||
| 780 | |||||||||||
| 781 | =over 4 | ||||||||||
| 782 | |||||||||||
| 783 | =item * | ||||||||||
| 784 | |||||||||||
| 785 | MetaCPAN | ||||||||||
| 786 | |||||||||||
| 787 | A modern, open-source CPAN search engine, useful to view POD in HTML format. | ||||||||||
| 788 | |||||||||||
| 789 | L<https://metacpan.org/release/HTML-Latemp-News> | ||||||||||
| 790 | |||||||||||
| 791 | =item * | ||||||||||
| 792 | |||||||||||
| 793 | Search CPAN | ||||||||||
| 794 | |||||||||||
| 795 | The default CPAN search engine, useful to view POD in HTML format. | ||||||||||
| 796 | |||||||||||
| 797 | L<http://search.cpan.org/dist/HTML-Latemp-News> | ||||||||||
| 798 | |||||||||||
| 799 | =item * | ||||||||||
| 800 | |||||||||||
| 801 | RT: CPAN's Bug Tracker | ||||||||||
| 802 | |||||||||||
| 803 | The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN. | ||||||||||
| 804 | |||||||||||
| 805 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Latemp-News> | ||||||||||
| 806 | |||||||||||
| 807 | =item * | ||||||||||
| 808 | |||||||||||
| 809 | AnnoCPAN | ||||||||||
| 810 | |||||||||||
| 811 | The AnnoCPAN is a website that allows community annotations of Perl module documentation. | ||||||||||
| 812 | |||||||||||
| 813 | L<http://annocpan.org/dist/HTML-Latemp-News> | ||||||||||
| 814 | |||||||||||
| 815 | =item * | ||||||||||
| 816 | |||||||||||
| 817 | CPAN Ratings | ||||||||||
| 818 | |||||||||||
| 819 | The CPAN Ratings is a website that allows community ratings and reviews of Perl modules. | ||||||||||
| 820 | |||||||||||
| 821 | L<http://cpanratings.perl.org/d/HTML-Latemp-News> | ||||||||||
| 822 | |||||||||||
| 823 | =item * | ||||||||||
| 824 | |||||||||||
| 825 | CPANTS | ||||||||||
| 826 | |||||||||||
| 827 | The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. | ||||||||||
| 828 | |||||||||||
| 829 | L<http://cpants.cpanauthors.org/dist/HTML-Latemp-News> | ||||||||||
| 830 | |||||||||||
| 831 | =item * | ||||||||||
| 832 | |||||||||||
| 833 | CPAN Testers | ||||||||||
| 834 | |||||||||||
| 835 | The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions. | ||||||||||
| 836 | |||||||||||
| 837 | L<http://www.cpantesters.org/distro/H/HTML-Latemp-News> | ||||||||||
| 838 | |||||||||||
| 839 | =item * | ||||||||||
| 840 | |||||||||||
| 841 | CPAN Testers Matrix | ||||||||||
| 842 | |||||||||||
| 843 | The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. | ||||||||||
| 844 | |||||||||||
| 845 | L<http://matrix.cpantesters.org/?dist=HTML-Latemp-News> | ||||||||||
| 846 | |||||||||||
| 847 | =item * | ||||||||||
| 848 | |||||||||||
| 849 | CPAN Testers Dependencies | ||||||||||
| 850 | |||||||||||
| 851 | The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. | ||||||||||
| 852 | |||||||||||
| 853 | L<http://deps.cpantesters.org/?module=HTML::Latemp::News> | ||||||||||
| 854 | |||||||||||
| 855 | =back | ||||||||||
| 856 | |||||||||||
| 857 | =head2 Bugs / Feature Requests | ||||||||||
| 858 | |||||||||||
| 859 | Please report any bugs or feature requests by email to C<bug-html-latemp-news at rt.cpan.org>, or through | ||||||||||
| 860 | the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=HTML-Latemp-News>. You will be automatically notified of any | ||||||||||
| 861 | progress on the request by the system. | ||||||||||
| 862 | |||||||||||
| 863 | =head2 Source Code | ||||||||||
| 864 | |||||||||||
| 865 | The code is open to the world, and available for you to hack on. Please feel free to browse it and play | ||||||||||
| 866 | with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull | ||||||||||
| 867 | from your repository :) | ||||||||||
| 868 | |||||||||||
| 869 | L<https://github.com/shlomif/html-latemp-news> | ||||||||||
| 870 | |||||||||||
| 871 | git clone git://github.com/shlomif/html-latemp-news.git | ||||||||||
| 872 | |||||||||||
| 873 | =cut | ||||||||||