| 1 | package Labyrinth::Plugin::CPAN::Content; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '3.55'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | Labyrinth::Plugin::CPAN::Content - Additional content for CPAN. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | The functions contain herein are for CPAN and CPAN Testers related page content. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # Libraries | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use base qw(Labyrinth::Plugin::Base); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Labyrinth::Support; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # Variables | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # this should be a config option | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # $settings{iheart_random} = 'http://iheart.cpantesters.org/home/random'; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | #---------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # Content Management Subroutines | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =head1 CONTENT MANAGEMENT FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =item GetSponsor | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Gets a random sponsor from the I <3 CPAN Testers website. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | sub GetSponsor { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $mech = WWW::Mechanize->new(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetSponsor: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $mech->agent_alias( 'Linux Mozilla' ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | eval { $mech->get( $settings{iheart_random} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return if($@ || !$mech->success() || !$mech->content()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$@ or not $mech->success or not $mech->content
$@ or not $mech->success
MC/DC0%0/3
$@ or not $mech->success or not $mech->content
$@
not $mech->success
not $mech->content
Truth table0%0/4
A or not(B) or not(C)
A= $@B= not $mech->successC= not $mech->content
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $json = $mech->content(); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $data = decode_json($json); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return unless($data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | $tvars{sponsor} = { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | title => $data->[0]->{links}[0]{title}, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | image => $data->[0]->{links}[0]{image}, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | body => $data->[0]->{links}[0]{body}, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | href => $data->[0]->{links}[0]{href}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | url => $data->[0]->{links}[0]{href} | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $tvars{sponsor}{url} =~ s!^https?://(?:www\.)?([^/]+).*!$1! if($tvars{sponsor}{url}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | L<Labyrinth> | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | Barbie, <barbie@missbarbell.co.uk> for | ||||||||||||||||||||||||||||||||||||||||||
| 83 | Miss Barbell Productions, L<http://www.missbarbell.co.uk/> | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Copyright (C) 2002-2015 Barbie for Miss Barbell Productions | ||||||||||||||||||||||||||||||||||||||||||
| 88 | All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 91 | modify it under the Artistic License 2.0. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||||||||||||||||