| 1 | package XML::Grammar::Fortune::Synd::App; | ||
| 2 | $XML::Grammar::Fortune::Synd::App::VERSION = '0.0400'; | ||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use parent 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use vars qw(@EXPORT); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | @EXPORT = ('run'); | ||
| 11 | |||
| 12 | 1 | ▶ | use Getopt::Long; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 0 | ▶ | use XML::Grammar::Fortune::Synd; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 16 | |||
| 17 | |||
| 18 | sub run | ||
| 19 | { | ||
| 20 | my $dir; | ||
| 21 | my $yaml_data_file; | ||
| 22 | my @xml_files = (); | ||
| 23 | my $atom_output_fn; | ||
| 24 | my $rss_output_fn; | ||
| 25 | my $master_url; | ||
| 26 | my $feed_title; | ||
| 27 | my $feed_tagline; | ||
| 28 | my $feed_author; | ||
| 29 | |||
| 30 | GetOptions( | ||
| 31 | 'dir=s' => \$dir, | ||
| 32 | 'xml-file=s' => \@xml_files, | ||
| 33 | 'yaml-data=s' => \$yaml_data_file, | ||
| 34 | 'atom-output=s' => \$atom_output_fn, | ||
| 35 | 'rss-output=s' => \$rss_output_fn, | ||
| 36 | 'master-url=s' => \$master_url, | ||
| 37 | 'title=s' => \$feed_title, | ||
| 38 | 'tagline=s' => \$feed_tagline, | ||
| 39 | 'author=s' => \$feed_author, | ||
| 40 | ); | ||
| 41 | |||
| 42 | my $url_callback = sub { | ||
| 43 | my ( $self, $args ) = @_; | ||
| 44 | |||
| 45 | my $id_obj = $args->{id_obj}; | ||
| 46 | |||
| 47 | my $base_fn = $id_obj->file(); | ||
| 48 | |||
| 49 | $base_fn =~ s{\.[^\.]*\z}{}ms; | ||
| 50 | |||
| 51 | return $master_url . $base_fn . ".html" . "#" . $id_obj->id(); | ||
| 52 | }; | ||
| 53 | |||
| 54 | my $syndicator = XML::Grammar::Fortune::Synd->new( | ||
| 55 | { | ||
| 56 | xml_files => \@xml_files, | ||
| 57 | url_callback => $url_callback, | ||
| 58 | } | ||
| 59 | ); | ||
| 60 | |||
| 61 | my @more_params; | ||
| 62 | |||
| 63 | if ($atom_output_fn) | ||
| 64 | { | ||
| 65 | my ( undef, undef, $atom_base ) = | ||
| 66 | File::Spec->splitpath($atom_output_fn); | ||
| 67 | push @more_params, ( atom_self_link => "$master_url$atom_base" ); | ||
| 68 | } | ||
| 69 | |||
| 70 | if ($rss_output_fn) | ||
| 71 | { | ||
| 72 | my ( undef, undef, $rss_base ) = File::Spec->splitpath($rss_output_fn); | ||
| 73 | push @more_params, ( rss_self_link => "$master_url$rss_base" ); | ||
| 74 | } | ||
| 75 | |||
| 76 | my $recent_ids_struct = $syndicator->calc_feeds( | ||
| 77 | { | ||
| 78 | yaml_persistence_file => $yaml_data_file, | ||
| 79 | yaml_persistence_file_out => $yaml_data_file, | ||
| 80 | xmls_dir => $dir, | ||
| 81 | feed_params => { | ||
| 82 | title => $feed_title, | ||
| 83 | 'link' => $master_url, | ||
| 84 | tagline => $feed_tagline, | ||
| 85 | author => $feed_author, | ||
| 86 | @more_params, | ||
| 87 | }, | ||
| 88 | } | ||
| 89 | ); | ||
| 90 | |||
| 91 | if ( defined($atom_output_fn) ) | ||
| 92 | { | ||
| 93 | open my $atom_out, ">", $atom_output_fn; | ||
| 94 | print {$atom_out} $recent_ids_struct->{'feeds'}->{'Atom'}->as_xml(); | ||
| 95 | close($atom_out); | ||
| 96 | } | ||
| 97 | |||
| 98 | if ( defined($rss_output_fn) ) | ||
| 99 | { | ||
| 100 | open my $rss20_out, ">", $rss_output_fn; | ||
| 101 | print {$rss20_out} $recent_ids_struct->{'feeds'}->{'rss20'}->as_xml(); | ||
| 102 | close($rss20_out); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | 1; | ||
| 106 | |||
| 107 | __END__ | ||