« SpreadRevolutionaryDate/MsgMaker/RevolutionaryDate/Calendar.pm
↑ Summary
SpreadRevolutionaryDate/Target.pm »
| 1 | # | ||||||||||||||||||||||||
| 2 | # This file is part of App-SpreadRevolutionaryDate | ||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2019-2026 by Gérald Sédrati. | ||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||
| 8 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||
| 10 | 8 | ▶ | use 5.014; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 8 | ▶ | use utf8; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | package App::SpreadRevolutionaryDate::Target::Twitter; | ||||||||||||||||||||||||
| 13 | 8 | $App::SpreadRevolutionaryDate::Target::Twitter::VERSION = '0.54'; | |||||||||||||||||||||||
| 14 | # ABSTRACT: Target class for L<App::SpreadRevolutionaryDate> to handle spreading on Twitter. | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 8 | ▶ | use Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 17 | 8 | with 'App::SpreadRevolutionaryDate::Target' | |||||||||||||||||||||||
| 18 | => {worker => 'Twitter::API__WITH__Twitter::API::Trait::ApiMethods'}; | ||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | 8 | ▶ | use Twitter::API; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||
| 22 | 8 | ▶ | use Locale::TextDomain 'App-SpreadRevolutionaryDate'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 23 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||
| 25 | 8 | has 'consumer_key' => ( | |||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||
| 27 | isa => 'Str', | ||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||
| 31 | 8 | has 'consumer_secret' => ( | |||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||
| 33 | isa => 'Str', | ||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 8 | has 'access_token' => ( | |||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||
| 39 | isa => 'Str', | ||||||||||||||||||||||||
| 40 | required => 1, | ||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 8 | has 'access_token_secret' => ( | |||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||
| 45 | isa => 'Str', | ||||||||||||||||||||||||
| 46 | required => 1, | ||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | 19 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||
| 51 | 19 | my ($orig, $class) = @_; | |||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 19 | my $args = $class->$orig(@_); | |||||||||||||||||||||||
| 54 | 19 | ▶ | my $api_1 = $args->{api} && $args->{api} eq 1 || 0; | ||||||||||||||||||||||
|
Condition80%4/5
$args->{'api'} && $args->{'api'} eq 1 || 0
$args->{"api"} and $args->{"api"} eq 1
MC/DC50%1/2
$args->{'api'} && $args->{'api'} eq 1 || 0
$args->{"api"}
$args->{"api"} eq 1
Truth table66%2/3
A and B
A= $args->{"api"}B= $args->{"api"} eq 1
| |||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | $args->{obj} = Twitter::API->new_with_traits( | ||||||||||||||||||||||||
| 57 | traits => 'ApiMethods', | ||||||||||||||||||||||||
| 58 | $api_1 ? | ||||||||||||||||||||||||
| 59 | () : | ||||||||||||||||||||||||
| 60 | (api_version => '2', api_ext => ''), | ||||||||||||||||||||||||
| 61 | consumer_key => $args->{consumer_key}, | ||||||||||||||||||||||||
| 62 | consumer_secret => $args->{consumer_secret}, | ||||||||||||||||||||||||
| 63 | access_token => $args->{access_token}, | ||||||||||||||||||||||||
| 64 | access_token_secret => $args->{access_token_secret}, | ||||||||||||||||||||||||
| 65 | 19 | ▶ | agent => 'RevolutionaryDate'); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 66 | 19 | return $args; | |||||||||||||||||||||||
| 67 | 8 | }; | |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||
| 70 | 14 | ▶ | sub spread { | ||||||||||||||||||||||
|
Subroutine
spread: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||
| 71 | 14 | my ($self, $msg, $test) = @_; | |||||||||||||||||||||||
| 72 | 14 | ▶ | $test //= 0; | ||||||||||||||||||||||
|
Condition50%1/2
$test //= 0
MC/DC0%0/1
$test //= 0
$test
Truth table50%1/2
A
A= $test
| |||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||
| 74 | # Multiline message | ||||||||||||||||||||||||
| 75 | 14 | $msg =~ s/\\n/\n/g; | |||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||
| 77 | 14 | ▶ | if ($test) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 78 | 14 | $msg = __("Spread on Twitter: ") . $msg; | |||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | 8 | ▶ | use open qw(:std :encoding(UTF-8)); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 81 | 8 | ▶ | use IO::Handle; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 82 | 14 | my $io = IO::Handle->new; | |||||||||||||||||||||||
| 83 | 14 | $io->fdopen(fileno(STDOUT), "w"); | |||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||
| 85 | 8 | ▶ | use Encode qw(encode decode is_utf8); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 86 | 14 | ▶ | $msg = encode('UTF-8', $msg) if is_utf8($msg); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | 14 | $io->say($msg); | |||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||
| 90 | 0 | $self->obj->post('tweets', {'-to_json' => {"text" => $msg}}); | |||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | 8 | ▶ | no Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 96 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||
| 98 | # A module must return a true value. Traditionally, a module returns 1. | ||||||||||||||||||||||||
| 99 | # But this module is a revolutionary one, so it discards all old traditions. | ||||||||||||||||||||||||
| 100 | # Idea borrowed from Jean Forget's DateTime::Calendar::FrenchRevolutionary. | ||||||||||||||||||||||||
| 101 | 8 | "Quand le gouvernement viole les droits du peuple, | |||||||||||||||||||||||
| 102 | l'insurrection est pour le peuple le plus sacré | ||||||||||||||||||||||||
| 103 | et le plus indispensable des devoirs"; | ||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||