SpreadRevolutionaryDate/Target/Bluesky.pm

filter: Statementstmt 83.0% 54 / 65 Branchbran 35.7% 5 / 14 Conditioncond 5.0% 1 / 20 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 60.3% 73 / 121 CC 16 SCAR 37.9
CC
16
Cov
61%
spread
73.9
BEGIN
1.0
BEGIN
1.0
CRAP 44.2
« SpreadRevolutionaryDate/Target/Mastodon.pm ↑ Summary SpreadRevolutionaryDate/Config.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 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 package App::SpreadRevolutionaryDate::Target::Bluesky;
13 5 $App::SpreadRevolutionaryDate::Target::Bluesky::VERSION = '0.54';
14 # ABSTRACT: Target class for L<App::SpreadRevolutionaryDate> to handle spreading on Bluesky.
15  
16 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 with 'App::SpreadRevolutionaryDate::Target'
18 => {worker => 'App::SpreadRevolutionaryDate::BlueskyLite'};
19  
20 5 ▶use App::SpreadRevolutionaryDate::BlueskyLite;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use Encode qw(encode decode is_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶use Locale::TextDomain 'App-SpreadRevolutionaryDate';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 5 has 'identifier' => (
27 is => 'ro',
28 isa => 'Str',
29 required => 1,
30 );
31  
32 5 has 'password' => (
33 is => 'ro',
34 isa => 'Str',
35 required => 1,
36 );
37  
38 5 has 'max_lenght' => (
39 is => 'ro',
40 isa => 'Int',
41 required => 1,
42 default => 250,
43 );
44  
45  
46 5 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 5 my ($orig, $class) = @_;
48  
49 5 my $args = $class->$orig(@_);
50  
51 $args->{obj} = App::SpreadRevolutionaryDate::BlueskyLite->new(
52 identifier => $args->{identifier},
53 password => $args->{password},
54 5 );
55 5 return $args;
56 5 };
57  
58  
59 1 ▶sub spread {
Subroutine spread: called CC=16 SCAR=43.0
Pod documented
60 1 my ($self, $msg, $test, $img) = @_;
61 1 ▶ $test //= 0;
Condition50%1/2
$test //= 0
l!l
10
MC/DC0%0/1
$test //= 0
$test
Truth table50%1/2
A
A= $test
Aresult
11
00
62  
63 # Multiline message
64 1 $msg =~ s/\\n/\n/g;
65  
66 1 ▶ if ($test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test) { } 1 0 1
67 1 $msg = __("Spread on Bluesky: ") . $msg;
68  
69 1 ▶ if ($img) {
Branch: 1 branch
BranchTrueFalseTotal
if ($img) 0 1 1
70 0 $msg .= " with image path: " . $img->{path} . " , alt: " . $img->{alt};
71 }
72  
73 5 ▶ use open qw(:std :encoding(UTF-8));
Subroutine BEGIN: called CC=1 SCAR=0.0
74 5 ▶ use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 my $io = IO::Handle->new;
76 1 $io->fdopen(fileno(STDOUT), "w");
77  
78 1 my @msgs = $self->_split_msg($msg, $self->max_lenght);
79  
80 1 ▶ for (my $i = 0; $i < scalar @msgs; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @msgs) 1 1 2
81 1 my $msg = "Message " . ($i+1) . ": " . $msgs[$i];
82 1 ▶ $msg = encode('UTF-8', $msg) if is_utf8($msg);
Branch: 1 branch
BranchTrueFalseTotal
if &is_utf8($msg) 1 0 1
83 1 $io->say($msg);
84 }
85 } else {
86 0 my @msgs = $self->_split_msg($msg, $self->max_lenght);
87 0 my $last_status;
88  
89 0 foreach my $msg (@msgs) {
90 0 ▶ if (!$last_status) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $last_status) { } 0 0 0
91 # First post
92 0 my $status = $self->obj->create_post($msg, $img);
93 0 ▶ if ($status && ref($status) eq 'HASH' && $status->{uri} && $status->{cid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}) 0 0 0
Condition0%0/9
$status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}
!ll&&!rl&&r
000
$status and ref $status eq "HASH" and $status->{"uri"}
!ll&&!rl&&r
000
$status and ref $status eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
$status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}
$status ref $status eq "HASH" $status->{"uri"} $status->{"cid"}
Truth table0%0/5
A and B and C and D
A= $statusB= ref $status eq "HASH"C= $status->{"uri"}D= $status->{"cid"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
94 $last_status = {
95 root => {
96 uri => $status->{uri},
97 cid => $status->{cid},
98 },
99 parent => {
100 uri => $status->{uri},
101 cid => $status->{cid},
102 }
103 0 };
104 }
105 } else {
106 # Next posts with reply_to
107 0 my $status = $self->obj->create_post($msg, undef, $last_status);
108 0 ▶ if ($status && ref($status) eq 'HASH' && $status->{uri} && $status->{cid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}) 0 0 0
Condition0%0/9
$status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}
!ll&&!rl&&r
000
$status and ref $status eq "HASH" and $status->{"uri"}
!ll&&!rl&&r
000
$status and ref $status eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
$status and ref $status eq "HASH" and $status->{"uri"} and $status->{"cid"}
$status ref $status eq "HASH" $status->{"uri"} $status->{"cid"}
Truth table0%0/5
A and B and C and D
A= $statusB= ref $status eq "HASH"C= $status->{"uri"}D= $status->{"cid"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
109 $last_status->{parent} = {
110 uri => $status->{uri},
111 cid => $status->{cid},
112 0 };
113 }
114 }
115 }
116 }
117 }
118  
119  
120 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 5 __PACKAGE__->meta->make_immutable;
122  
123 # A module must return a true value. Traditionally, a module returns 1.
124 # But this module is a revolutionary one, so it discards all old traditions.
125 # Idea borrowed from Jean Forget's DateTime::Calendar::FrenchRevolutionary.
126 5 "Quand le gouvernement viole les droits du peuple,
127 l'insurrection est pour le peuple le plus sacré
128 et le plus indispensable des devoirs";
129  
130 __END__
« SpreadRevolutionaryDate/Target/Mastodon.pm ↑ Summary SpreadRevolutionaryDate/Config.pm »