| 1 | package XML::Grammar::Fortune::Synd::App; | ||
| 2 | $XML::Grammar::Fortune::Synd::App::VERSION = '0.0214'; | ||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 2 | ▶ | use parent 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | ▶ | use vars qw(@EXPORT); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | @EXPORT=('run'); | ||
| 11 | |||
| 12 | 2 | ▶ | use Getopt::Long; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 2 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 2 | ▶ | use XML::Grammar::Fortune::Synd; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | sub run | ||
| 20 | { | ||
| 21 | my $dir; | ||
| 22 | my $yaml_data_file; | ||
| 23 | my @xml_files = (); | ||
| 24 | my $atom_output_fn; | ||
| 25 | my $rss_output_fn; | ||
| 26 | my $master_url; | ||
| 27 | my $feed_title; | ||
| 28 | my $feed_tagline; | ||
| 29 | my $feed_author; | ||
| 30 | |||
| 31 | GetOptions( | ||
| 32 | 'dir=s' => \$dir, | ||
| 33 | 'xml-file=s' => \@xml_files, | ||
| 34 | 'yaml-data=s' => \$yaml_data_file, | ||
| 35 | 'atom-output=s' => \$atom_output_fn, | ||
| 36 | 'rss-output=s' => \$rss_output_fn, | ||
| 37 | 'master-url=s' => \$master_url, | ||
| 38 | 'title=s' => \$feed_title, | ||
| 39 | 'tagline=s' => \$feed_tagline, | ||
| 40 | 'author=s' => \$feed_author, | ||
| 41 | ); | ||
| 42 | |||
| 43 | |||
| 44 | my $url_callback = sub { | ||
| 45 | my ($self, $args) = @_; | ||
| 46 | |||
| 47 | my $id_obj = $args->{id_obj}; | ||
| 48 | |||
| 49 | my $base_fn = $id_obj->file(); | ||
| 50 | |||
| 51 | $base_fn =~ s{\.[^\.]*\z}{}ms; | ||
| 52 | |||
| 53 | return $master_url . $base_fn . ".html" . "#" . $id_obj->id(); | ||
| 54 | }; | ||
| 55 | |||
| 56 | my $syndicator = XML::Grammar::Fortune::Synd->new( | ||
| 57 | { | ||
| 58 | xml_files => \@xml_files, | ||
| 59 | url_callback => $url_callback, | ||
| 60 | } | ||
| 61 | ); | ||
| 62 | |||
| 63 | my @more_params; | ||
| 64 | |||
| 65 | if ($atom_output_fn) | ||
| 66 | { | ||
| 67 | my (undef, undef, $atom_base) = File::Spec->splitpath($atom_output_fn); | ||
| 68 | push @more_params, (atom_self_link => "$master_url$atom_base"); | ||
| 69 | } | ||
| 70 | |||
| 71 | if ($rss_output_fn) | ||
| 72 | { | ||
| 73 | my (undef, undef, $rss_base) = File::Spec->splitpath($rss_output_fn); | ||
| 74 | push @more_params, (rss_self_link => "$master_url$rss_base"); | ||
| 75 | } | ||
| 76 | |||
| 77 | my $recent_ids_struct = $syndicator->calc_feeds( | ||
| 78 | { | ||
| 79 | yaml_persistence_file => $yaml_data_file, | ||
| 80 | yaml_persistence_file_out => $yaml_data_file, | ||
| 81 | xmls_dir => $dir, | ||
| 82 | feed_params => | ||
| 83 | { | ||
| 84 | title => $feed_title, | ||
| 85 | 'link' => $master_url, | ||
| 86 | tagline => $feed_tagline, | ||
| 87 | author => $feed_author, | ||
| 88 | @more_params, | ||
| 89 | }, | ||
| 90 | } | ||
| 91 | ); | ||
| 92 | |||
| 93 | if (defined($atom_output_fn)) | ||
| 94 | { | ||
| 95 | open my $atom_out, ">", $atom_output_fn; | ||
| 96 | print {$atom_out} $recent_ids_struct->{'feeds'}->{'Atom'}->as_xml(); | ||
| 97 | close($atom_out); | ||
| 98 | } | ||
| 99 | |||
| 100 | if (defined($rss_output_fn)) | ||
| 101 | { | ||
| 102 | open my $rss20_out, ">", $rss_output_fn; | ||
| 103 | print {$rss20_out} $recent_ids_struct->{'feeds'}->{'rss20'}->as_xml(); | ||
| 104 | close($rss20_out); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | 1; | ||
| 108 | |||
| 109 | __END__ | ||
| 110 | |||
| 111 | =pod | ||
| 112 | |||
| 113 | =encoding UTF-8 | ||
| 114 | |||
| 115 | =head1 NAME | ||
| 116 | |||
| 117 | XML::Grammar::Fortune::Synd::App - module implementing a command line | ||
| 118 | application to syndicate FortuneXML as Atom/RSS. | ||
| 119 | |||
| 120 | =head1 VERSION | ||
| 121 | |||
| 122 | version 0.0214 | ||
| 123 | |||
| 124 | =head1 SYNOPSIS | ||
| 125 | |||
| 126 | perl -MXML::Grammar::Fortune::Synd::App -e 'run()' [ARGS] \ | ||
| 127 | |||
| 128 | =head1 FUNCTIONS | ||
| 129 | |||
| 130 | =head2 run() | ||
| 131 | |||
| 132 | Call with no arguments to run the application from the commandline. | ||
| 133 | |||
| 134 | =head1 AUTHOR | ||
| 135 | |||
| 136 | Shlomi Fish <shlomif@cpan.org> | ||
| 137 | |||
| 138 | =head1 COPYRIGHT AND LICENSE | ||
| 139 | |||
| 140 | This software is Copyright (c) 2019 by Shlomi Fish. | ||
| 141 | |||
| 142 | This is free software, licensed under: | ||
| 143 | |||
| 144 | The MIT (X11) License | ||
| 145 | |||
| 146 | =head1 BUGS | ||
| 147 | |||
| 148 | Please report any bugs or feature requests on the bugtracker website | ||
| 149 | L<https://github.com/shlomif/fortune-xml/issues> | ||
| 150 | |||
| 151 | When submitting a bug or request, please include a test-file or a | ||
| 152 | patch to an existing test-file that illustrates the bug or desired | ||
| 153 | feature. | ||
| 154 | |||
| 155 | =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan | ||
| 156 | |||
| 157 | =head1 SUPPORT | ||
| 158 | |||
| 159 | =head2 Perldoc | ||
| 160 | |||
| 161 | You can find documentation for this module with the perldoc command. | ||
| 162 | |||
| 163 | perldoc XML::Grammar::Fortune::Synd::App | ||
| 164 | |||
| 165 | =head2 Websites | ||
| 166 | |||
| 167 | The following websites have more information about this module, and may be of help to you. As always, | ||
| 168 | in addition to those websites please use your favorite search engine to discover more resources. | ||
| 169 | |||
| 170 | =over 4 | ||
| 171 | |||
| 172 | =item * | ||
| 173 | |||
| 174 | MetaCPAN | ||
| 175 | |||
| 176 | A modern, open-source CPAN search engine, useful to view POD in HTML format. | ||
| 177 | |||
| 178 | L<https://metacpan.org/release/XML-Grammar-Fortune-Synd> | ||
| 179 | |||
| 180 | =item * | ||
| 181 | |||
| 182 | Search CPAN | ||
| 183 | |||
| 184 | The default CPAN search engine, useful to view POD in HTML format. | ||
| 185 | |||
| 186 | L<http://search.cpan.org/dist/XML-Grammar-Fortune-Synd> | ||
| 187 | |||
| 188 | =item * | ||
| 189 | |||
| 190 | RT: CPAN's Bug Tracker | ||
| 191 | |||
| 192 | The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN. | ||
| 193 | |||
| 194 | L<https://rt.cpan.org/Public/Dist/Display.html?Name=XML-Grammar-Fortune-Synd> | ||
| 195 | |||
| 196 | =item * | ||
| 197 | |||
| 198 | AnnoCPAN | ||
| 199 | |||
| 200 | The AnnoCPAN is a website that allows community annotations of Perl module documentation. | ||
| 201 | |||
| 202 | L<http://annocpan.org/dist/XML-Grammar-Fortune-Synd> | ||
| 203 | |||
| 204 | =item * | ||
| 205 | |||
| 206 | CPAN Ratings | ||
| 207 | |||
| 208 | The CPAN Ratings is a website that allows community ratings and reviews of Perl modules. | ||
| 209 | |||
| 210 | L<http://cpanratings.perl.org/d/XML-Grammar-Fortune-Synd> | ||
| 211 | |||
| 212 | =item * | ||
| 213 | |||
| 214 | CPANTS | ||
| 215 | |||
| 216 | The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution. | ||
| 217 | |||
| 218 | L<http://cpants.cpanauthors.org/dist/XML-Grammar-Fortune-Synd> | ||
| 219 | |||
| 220 | =item * | ||
| 221 | |||
| 222 | CPAN Testers | ||
| 223 | |||
| 224 | The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions. | ||
| 225 | |||
| 226 | L<http://www.cpantesters.org/distro/X/XML-Grammar-Fortune-Synd> | ||
| 227 | |||
| 228 | =item * | ||
| 229 | |||
| 230 | CPAN Testers Matrix | ||
| 231 | |||
| 232 | The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. | ||
| 233 | |||
| 234 | L<http://matrix.cpantesters.org/?dist=XML-Grammar-Fortune-Synd> | ||
| 235 | |||
| 236 | =item * | ||
| 237 | |||
| 238 | CPAN Testers Dependencies | ||
| 239 | |||
| 240 | The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. | ||
| 241 | |||
| 242 | L<http://deps.cpantesters.org/?module=XML::Grammar::Fortune::Synd> | ||
| 243 | |||
| 244 | =back | ||
| 245 | |||
| 246 | =head2 Bugs / Feature Requests | ||
| 247 | |||
| 248 | Please report any bugs or feature requests by email to C<bug-xml-grammar-fortune-synd at rt.cpan.org>, or through | ||
| 249 | the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=XML-Grammar-Fortune-Synd>. You will be automatically notified of any | ||
| 250 | progress on the request by the system. | ||
| 251 | |||
| 252 | =head2 Source Code | ||
| 253 | |||
| 254 | The code is open to the world, and available for you to hack on. Please feel free to browse it and play | ||
| 255 | with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull | ||
| 256 | from your repository :) | ||
| 257 | |||
| 258 | L<https://github.com/shlomif/fortune-xml> | ||
| 259 | |||
| 260 | git clone git://github.com/shlomif/fortune-xml.git | ||
| 261 | |||
| 262 | =cut | ||