| 1 | package FilmAffinity::Utils; | ||||||||||
| 2 | |||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 12 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 12 | ▶ | use LWP::RobotUA; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | FilmAffinity::Utils - Utils for FilmAffinity | ||||||||||
| 12 | |||||||||||
| 13 | =head1 VERSION | ||||||||||
| 14 | |||||||||||
| 15 | Version 1.01 | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | 12 | our $VERSION = 1.01; | |||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use FilmAffinity::Utils; | ||||||||||
| 24 | |||||||||||
| 25 | my $string = demoronize($string); | ||||||||||
| 26 | my $ua = buildRobot($delay); | ||||||||||
| 27 | my $tsv = data2tsv($data); | ||||||||||
| 28 | |||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||
| 30 | |||||||||||
| 31 | Several utilities functions | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 12 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 12 | our @EXPORT_OK = qw/demoronize buildRobot data2tsv/; | |||||||||
| 37 | |||||||||||
| 38 | 12 | Readonly::Scalar my $SECONDS => 60; | |||||||||
| 39 | |||||||||||
| 40 | =head1 SUBROUTINES/METHODS | ||||||||||
| 41 | |||||||||||
| 42 | =head2 demoronize | ||||||||||
| 43 | |||||||||||
| 44 | Remove funky Windows 'smart' characters. | ||||||||||
| 45 | |||||||||||
| 46 | Most of this code is borrowed from Catalyst::Plugin::Params::Demoronize | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | 142 | ▶ | sub demoronize { | ||||||||
|
Subroutine
demoronize: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 51 | 142 | my $str = shift; | |||||||||
| 52 | |||||||||||
| 53 | 142 | ▶ | return $str unless defined $str; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 141 | my $demoronizeReplaceMap = { | |||||||||
| 56 | q{\x{201A}|\x82} => q{,}, # 82, SINGLE LOW-9 QUOTATION MARK | ||||||||||
| 57 | q{\x{201E}|\x84} => q{,,}, # 84, DOUBLE LOW-9 QUOTATION MARK | ||||||||||
| 58 | q{\x{2026}|\x85} => q{...}, # 85, HORIZONTAL ELLIPSIS | ||||||||||
| 59 | q{\x{02C6}|\x88} => q{^}, # 88, MODIFIER LETTER CIRCUMFLEX ACCENT | ||||||||||
| 60 | q{\x{2018}|\x91} => q{`}, # 91, LEFT SINGLE QUOTATION MARK | ||||||||||
| 61 | q{\x{2019}|\x92} => q{'}, # 92, RIGHT SINGLE QUOTATION MARK | ||||||||||
| 62 | q{\x{201C}|\x93} => q{"}, # 93, LEFT DOUBLE QUOTATION MARK | ||||||||||
| 63 | q{\x{201D}|\x94} => q{"}, # 94, RIGHT DOUBLE QUOTATION MARK | ||||||||||
| 64 | q{\x{2022}|\x95|•} => q{*}, # 95, BULLET | ||||||||||
| 65 | q{\x{2013}|\x96} => q{-}, # 96, EN DASH | ||||||||||
| 66 | q{\x{2014}|\x97} => q{-}, # 97, EM DASH | ||||||||||
| 67 | q{\x{2039}|\x8B} => q{<}, # 8B, SINGLE LEFT-POINTING ANGLE QUOTATION MARK | ||||||||||
| 68 | q{\x{203A}|\x9B} => q{>}, # 9B, SINGLE RIGHT-POINTING ANGLE QUOTATION MARK | ||||||||||
| 69 | }; | ||||||||||
| 70 | |||||||||||
| 71 | 141 | foreach my $replace ( keys %{$demoronizeReplaceMap} ) { | |||||||||
| 72 | 1833 | my $replacement = $demoronizeReplaceMap->{$replace}; | |||||||||
| 73 | 1833 | $str =~ s/$replace/$replacement/xmsg; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 141 | return $str; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | =head2 buildRobot | ||||||||||
| 80 | |||||||||||
| 81 | Returns a LWP::RobotUA for web requests | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 14 | ▶ | sub buildRobot { | ||||||||
|
Subroutine
buildRobot: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 86 | 14 | my ($delay) = shift; | |||||||||
| 87 | |||||||||||
| 88 | 14 | my $ua = LWP::RobotUA->new( "FilmAffinity-Bot/$VERSION", 'me@foo.com' ); | |||||||||
| 89 | 14 | $ua->timeout($SECONDS); | |||||||||
| 90 | 14 | $ua->env_proxy; | |||||||||
| 91 | 14 | $ua->delay( $delay / $SECONDS ); | |||||||||
| 92 | |||||||||||
| 93 | 14 | return $ua; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | =head2 data2tsv | ||||||||||
| 97 | |||||||||||
| 98 | Transform FilmAffinity::UserRating in tab separated value | ||||||||||
| 99 | |||||||||||
| 100 | Returns a tsv string | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | 2 | ▶ | sub data2tsv { | ||||||||
|
Subroutine
data2tsv: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 105 | 2 | my ($data) = shift; | |||||||||
| 106 | |||||||||||
| 107 | 2 | my $tsvString; | |||||||||
| 108 | 2 | foreach my $mov ( sort { p_sortByRatings($data) } keys %{$data} ) { | |||||||||
| 109 | $tsvString .= $mov . "\t" . $data->{$mov}{'title'} . "\t" | ||||||||||
| 110 | 6 | . $data->{$mov}{'rating'} . "\n"; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 2 | return $tsvString; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 9 | ▶ | sub p_sortByRatings { | ||||||||
|
Subroutine
p_sortByRatings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 117 | 9 | my ($ref_movies) = @_; | |||||||||
| 118 | 9 | return $ref_movies->{$b}{'rating'} <=> $ref_movies->{$a}{'rating'}; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | =head1 AUTHOR | ||||||||||
| 122 | |||||||||||
| 123 | William Belle, C<< <william.belle at gmail.com> >> | ||||||||||
| 124 | |||||||||||
| 125 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 126 | |||||||||||
| 127 | Please report any bugs or feature requests to C<bug-filmaffinity-userrating at rt.cpan.org>, or through | ||||||||||
| 128 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FilmAffinity-UserRating>. I will be notified, and then you'll | ||||||||||
| 129 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 SUPPORT | ||||||||||
| 132 | |||||||||||
| 133 | You can find documentation for this module with the perldoc command. | ||||||||||
| 134 | |||||||||||
| 135 | perldoc FilmAffinity::Utils | ||||||||||
| 136 | |||||||||||
| 137 | You can also look for information at: | ||||||||||
| 138 | |||||||||||
| 139 | =over 4 | ||||||||||
| 140 | |||||||||||
| 141 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 142 | |||||||||||
| 143 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FilmAffinity-UserRating> | ||||||||||
| 144 | |||||||||||
| 145 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 146 | |||||||||||
| 147 | L<http://annocpan.org/dist/FilmAffinity-UserRating> | ||||||||||
| 148 | |||||||||||
| 149 | =item * CPAN Ratings | ||||||||||
| 150 | |||||||||||
| 151 | L<http://cpanratings.perl.org/d/FilmAffinity-UserRating> | ||||||||||
| 152 | |||||||||||
| 153 | =item * Search CPAN | ||||||||||
| 154 | |||||||||||
| 155 | L<http://search.cpan.org/dist/FilmAffinity-UserRating/> | ||||||||||
| 156 | |||||||||||
| 157 | =back | ||||||||||
| 158 | |||||||||||
| 159 | =head1 SEE ALSO | ||||||||||
| 160 | |||||||||||
| 161 | L<http://www.filmaffinity.com> | ||||||||||
| 162 | |||||||||||
| 163 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 164 | |||||||||||
| 165 | Copyright 2013 William Belle. | ||||||||||
| 166 | |||||||||||
| 167 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 168 | under the terms of either: the GNU General Public License as published | ||||||||||
| 169 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 170 | |||||||||||
| 171 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 12 | 1; # End of FilmAffinity::Utils | |||||||||