Skip to content

Commit 9ba29d8

Browse files
authored
Merge pull request #38 from openSUSE/perltidy
Check for perltidy violations
2 parents f580c3b + d2af546 commit 9ba29d8

21 files changed

Lines changed: 197 additions & 155 deletions

File tree

.github/workflows/perltidy.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: perltidy
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
tags-ignore:
7+
- '*'
8+
pull_request:
9+
jobs:
10+
perltidy:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: perl:5.32
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: perl -V
17+
run: perl -V
18+
- name: Install dependencies
19+
run: cpanm -n Perl::Tidy
20+
- name: perltidy --version
21+
run: perltidy --version
22+
- name: Run perltidy
23+
shell: bash
24+
run: |
25+
shopt -s extglob globstar nullglob
26+
perltidy --pro=.../.perltidyrc -b -bext='/' **/*.p[lm] **/*.t && git diff --exit-code

lib/Mojo/IOLoop/ReadWriteProcess.pm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ has session => sub { Mojo::IOLoop::ReadWriteProcess::Session->singleton };
5656

5757
has _deparse => sub { B::Deparse->new }
5858
if DEBUG;
59-
has _deserialize => sub { \&Storable::thaw };
60-
has _serialize => sub { \&Storable::freeze };
59+
has _deserialize => sub { \&Storable::thaw };
60+
has _serialize => sub { \&Storable::freeze };
6161
has _default_kill_signal => POSIX::SIGTERM;
6262
has _default_blocking_signal => POSIX::SIGKILL;
6363

@@ -76,7 +76,7 @@ sub to_ioloop {
7676
my $me = $$;
7777
$stream->on(
7878
close => sub {
79-
return unless $$ == $me;
79+
return unless $$ == $me;
8080
$self->_collect->stop unless defined $self->_status;
8181
});
8282
return $stream;
@@ -396,10 +396,11 @@ sub exit_status {
396396
sub restart {
397397
$_[0]->is_running ? $_[0]->stop->start : $_[0]->start;
398398
}
399+
399400
sub is_running {
400-
my ($self) = shift;
401-
$self->session->consume_collected_info;
402-
$self->process_id ? kill 0 => $self->process_id : 0;
401+
my ($self) = shift;
402+
$self->session->consume_collected_info;
403+
$self->process_id ? kill 0 => $self->process_id : 0;
403404
}
404405

405406
sub write_pidfile {
@@ -513,7 +514,7 @@ sub stop {
513514
my $self = shift;
514515

515516
my $pid = $self->pid;
516-
return $self unless defined $pid;
517+
return $self unless defined $pid;
517518
return $self->_shutdown(1) unless $self->is_running;
518519
$self->_diag("Stopping $pid") if DEBUG;
519520

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v1/Cpuset.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ sub sched_relax_domain_level {
5858
sub sched_load_balance {
5959
shift->cgroup->_flag(SCHED_LOAD_BALANCE_INTERFACE, @_);
6060
}
61-
sub memory_spread_slab { shift->cgroup->_flag(MEM_SPREAD_SLAB_INTERFACE, @_) }
62-
sub memory_spread_page { shift->cgroup->_flag(MEM_SPREAD_PAGE_INTERFACE, @_) }
61+
sub memory_spread_slab { shift->cgroup->_flag(MEM_SPREAD_SLAB_INTERFACE, @_) }
62+
sub memory_spread_page { shift->cgroup->_flag(MEM_SPREAD_PAGE_INTERFACE, @_) }
6363
sub get_memory_pressure { shift->cgroup->_list(MEM_PRESSURE_INTERFACE) }
64-
sub mem_hardwall { shift->cgroup->_flag(MEM_HARDWALL_INTERFACE, @_) }
65-
sub mem_exclusive { shift->cgroup->_flag(MEM_EXCLUSIVE_INTERFACE, @_) }
66-
sub cpu_exclusive { shift->cgroup->_flag(CPU_EXCLUSIVE_INTERFACE, @_) }
64+
sub mem_hardwall { shift->cgroup->_flag(MEM_HARDWALL_INTERFACE, @_) }
65+
sub mem_exclusive { shift->cgroup->_flag(MEM_EXCLUSIVE_INTERFACE, @_) }
66+
sub cpu_exclusive { shift->cgroup->_flag(CPU_EXCLUSIVE_INTERFACE, @_) }
6767
sub memory_migrate { shift->cgroup->_flag(MEMORY_MIGRATE_INTERFACE, @_) }
6868

6969
1;

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v2/CPU.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use constant {
1212
has cgroup => sub { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new };
1313

1414
sub stat { shift->cgroup->_list(STAT_INTERFACE) }
15-
sub weight { shift->cgroup->_setget(WEIGHT_INTERFACE, @_) }
15+
sub weight { shift->cgroup->_setget(WEIGHT_INTERFACE, @_) }
1616
sub weight_nice { shift->cgroup->_setget(WEIGHT_NICE_INTERFACE, @_) }
17-
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
17+
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
1818

1919
1;
2020

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v2/IO.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ has cgroup => sub { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new };
1212

1313
sub stat { shift->cgroup->_list(STAT_INTERFACE) }
1414
sub weight { shift->cgroup->_setget(WEIGHT_INTERFACE, @_) }
15-
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
15+
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
1616

1717
1;
1818

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v2/Memory.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ has cgroup => sub { Mojo::IOLoop::ReadWriteProcess::CGroup::v2->new };
1818

1919
sub current { shift->cgroup->_list(CURRENT_INTERFACE) }
2020
sub swap_current { shift->cgroup->_list(SWAP_CURRENT_INTERFACE) }
21-
sub low { shift->cgroup->_setget(LOW_INTERFACE, @_) }
22-
sub high { shift->cgroup->_setget(HIGH_INTERFACE, @_) }
23-
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
21+
sub low { shift->cgroup->_setget(LOW_INTERFACE, @_) }
22+
sub high { shift->cgroup->_setget(HIGH_INTERFACE, @_) }
23+
sub max { shift->cgroup->_setget(MAX_INTERFACE, @_) }
2424
sub swap_max { shift->cgroup->_setget(SWAP_MAX_INTERFACE, @_) }
2525
sub events { shift->cgroup->_list(EVENTS_INTERFACE) }
2626
sub stat { shift->cgroup->_list(STAT_INTERFACE) }

lib/Mojo/IOLoop/ReadWriteProcess/Session.pm

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ sub enable {
5656
while ((my $pid = waitpid(-1, WNOHANG)) > 0) {
5757
$singleton->add_collected_info($pid, $?, $!);
5858
}
59-
$singleton->consume_collected_info() if ($singleton->emit_from_sigchld());
59+
$singleton->consume_collected_info()
60+
if ($singleton->emit_from_sigchld());
6061
}
6162
});
6263
}
@@ -84,14 +85,14 @@ sub collect {
8485
}
8586

8687
sub consume_collected_info {
87-
while(my $i = shift @{$singleton->collected_info}) {
88-
$singleton->collect(@$i)
89-
}
88+
while (my $i = shift @{$singleton->collected_info}) {
89+
$singleton->collect(@$i);
90+
}
9091
}
9192

9293
sub add_collected_info {
93-
shift;
94-
push @{$singleton->collected_info}, [@_];
94+
shift;
95+
push @{$singleton->collected_info}, [@_];
9596
}
9697

9798
# Use as $pid => Mojo::IOLoop::ReadWriteProcess
@@ -135,7 +136,11 @@ sub contains {
135136
$singleton->all->grep(sub { $_->pid eq $pid })->size == 1;
136137
}
137138

138-
sub reset { @{+shift}{qw(events orphans process_table collected_info handler emit_from_sigchld)} = ({}, {}, {}, [], undef, 1) }
139+
sub reset {
140+
@{+shift}
141+
{qw(events orphans process_table collected_info handler emit_from_sigchld)}
142+
= ({}, {}, {}, [], undef, 1);
143+
}
139144

140145
# XXX: This should be replaced by PR_GET_CHILD_SUBREAPER
141146
sub disable_subreaper {

lib/Mojo/IOLoop/ReadWriteProcess/Shared/Memory.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use Exporter 'import';
1515

1616
has key => sub { Mojo::IOLoop::ReadWriteProcess::Shared::Semaphore::_genkey() };
1717
has 'buffer';
18-
has destroy => 0;
19-
has flags => S_IRWXU() | S_IRWXG() | IPC_CREAT();
18+
has destroy => 0;
19+
has flags => S_IRWXU() | S_IRWXG() | IPC_CREAT();
2020
has lock_flags => IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
2121
| S_IROTH | S_IWOTH;
2222
has _size => 10 * 1024;

lib/Mojo/IOLoop/ReadWriteProcess/Shared/Semaphore.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ our @EXPORT_OK = qw(semaphore);
1010
use Exporter 'import';
1111

1212
use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG};
13-
has key => sub { shift->_genkey };
14-
has _sem => sub { $_[0]->_create(shift->key) };
13+
has key => sub { shift->_genkey };
14+
has _sem => sub { $_[0]->_create(shift->key) };
1515
has count => 1;
1616
has _value => 1;
17-
has flags => IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
17+
has flags => IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
1818
| S_IROTH | S_IWOTH;
1919

2020
sub semaphore { __PACKAGE__->new(@_) }

t/01_run.t

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ subtest 'process basic functions' => sub {
3535
$p->start();
3636
$p->stop();
3737
};
38-
ok $@, "Error expected";
38+
ok $@, "Error expected";
3939
like $@, qr/Nothing to do/,
4040
"Process with no code nor execute command, will fail";
4141

@@ -88,8 +88,8 @@ subtest 'process is_running()' => sub {
8888

8989
close(PARENT);
9090
chomp @output;
91-
is $output[0], "FOOBARFTW", 'right output from process';
92-
is $p->is_running, 0, "Process now is stopped";
91+
is $output[0], "FOOBARFTW", 'right output from process';
92+
is $p->is_running, 0, "Process now is stopped";
9393

9494
# Redefine new code and restart it.
9595
pipe(PARENT, CHILD);
@@ -106,8 +106,8 @@ subtest 'process is_running()' => sub {
106106
@output = scalar <PARENT>;
107107
$p->stop();
108108
chomp @output;
109-
is $output[0], "FOOBAZFTW", 'right output from process';
110-
is $p->is_running, 0, "Process now is not running";
109+
is $output[0], "FOOBAZFTW", 'right output from process';
110+
is $p->is_running, 0, "Process now is not running";
111111
@output = ('');
112112

113113
pipe(PARENT, CHILD);
@@ -146,7 +146,7 @@ subtest 'process execute()' => sub {
146146
)->start();
147147
is $p->getline, "TEST normal print\n", 'Get right output from stdout';
148148
is $p->err_getline, "TEST error print\n", 'Get right output from stderr';
149-
is $p->is_running, 1, 'process is still waiting for our input';
149+
is $p->is_running, 1, 'process is still waiting for our input';
150150
$p->write("FOOBAR");
151151
is $p->read, "you entered FOOBAR\n",
152152
'process received input and printed it back';
@@ -163,7 +163,7 @@ subtest 'process execute()' => sub {
163163
])->start();
164164
is $p->stdout, "TEST normal print\n", 'Get right output from stdout';
165165
is $p->err_getline, "TEST error print\n", 'Get right output from stderr';
166-
is $p->is_running, 1, 'process is still waiting for our input';
166+
is $p->is_running, 1, 'process is still waiting for our input';
167167
$p->write("FOOBAR");
168168
is $p->getline, "you entered FOOBAR\n",
169169
'process received input and printed it back';
@@ -178,7 +178,7 @@ subtest 'process execute()' => sub {
178178
)->args([qw(FOO BAZ)])->start();
179179
is $p->stdout, "TEST normal print\n", 'Get right output from stdout';
180180
is $p->err_getline, "TEST error print\n", 'Get right output from stderr';
181-
is $p->is_running, 1, 'process is still waiting for our input';
181+
is $p->is_running, 1, 'process is still waiting for our input';
182182
$p->write("FOOBAR");
183183
is $p->getline, "you entered FOOBAR\n",
184184
'process received input and printed it back';
@@ -224,8 +224,8 @@ subtest 'process execute()' => sub {
224224
); # ;)
225225
$p->start();
226226
$p->stop();
227-
is $p->is_running, 1, 'process is still running';
228-
is $p->_status, undef, 'no status yet';
227+
is $p->is_running, 1, 'process is still running';
228+
is $p->_status, undef, 'no status yet';
229229
my $err = ${(@{$p->error})[0]};
230230
my $exp = qr/Could not kill process/;
231231
like $err, $exp, 'Error is not empty if process could not be killed';
@@ -266,8 +266,8 @@ subtest 'process execute()' => sub {
266266
pidfile => $pidfile
267267
)->start();
268268
my $pid = path($pidfile)->slurp();
269-
is -e $pidfile, 1, 'Pidfile is there!';
270-
is $pid, $p->pid, "Pidfile was correctly written";
269+
is -e $pidfile, 1, 'Pidfile is there!';
270+
is $pid, $p->pid, "Pidfile was correctly written";
271271
$p->stop();
272272
is -e $pidfile, undef, 'Pidfile got removed after stop()';
273273

@@ -283,8 +283,8 @@ subtest 'process execute()' => sub {
283283
)->start();
284284
$p->write_pidfile($pidfile);
285285
$pid = path($pidfile)->slurp();
286-
is -e $pidfile, 1, 'Pidfile is there!';
287-
is $pid, $p->pid, "Pidfile was correctly written";
286+
is -e $pidfile, 1, 'Pidfile is there!';
287+
is $pid, $p->pid, "Pidfile was correctly written";
288288
$p->stop();
289289
is -e $pidfile, undef, 'Pidfile got removed after stop()';
290290

@@ -304,7 +304,12 @@ subtest 'process execute()' => sub {
304304
subtest 'process(execute =>"/usr/bin/true")' => sub {
305305
plan skip_all => "Missing '/usr/bin/true'" unless -e '/usr/bin/true';
306306

307-
is(process(execute => '/usr/bin/true')->quirkiness(1)->start()->wait_stop()->exit_status(), 0, 'Simple exec of "/usr/bin/true" return 0');
307+
is(
308+
process(execute => '/usr/bin/true')->quirkiness(1)->start()->wait_stop()
309+
->exit_status(),
310+
0,
311+
'Simple exec of "/usr/bin/true" return 0'
312+
);
308313
};
309314

310315
subtest 'process code()' => sub {
@@ -464,7 +469,7 @@ subtest 'process code()' => sub {
464469
$p->write("a");
465470
$p->wait_stop();
466471
like $p->stderr_all, qr/TEST error print/, 'read all from stderr works';
467-
is $p->read_all, '', 'stdout is empty';
472+
is $p->read_all, '', 'stdout is empty';
468473
};
469474

470475
subtest stop_whole_process_group_gracefully => sub {
@@ -546,46 +551,65 @@ process';
546551

547552
subtest 'process_args' => sub {
548553
my $code = sub {
549-
shift;
550-
print $_.$/ for(@_);
554+
shift;
555+
print "$_$/" for @_;
551556
};
552557

553-
my $p = Mojo::IOLoop::ReadWriteProcess->new($code, args => '0' )->start->wait_stop();
558+
my $p = Mojo::IOLoop::ReadWriteProcess->new($code, args => '0')
559+
->start->wait_stop();
554560
is($p->read_all_stdout(), "0$/", '1) False scalar value was given as args.');
555561

556-
$p = Mojo::IOLoop::ReadWriteProcess->new($code)->args('0')->start->wait_stop();
562+
$p
563+
= Mojo::IOLoop::ReadWriteProcess->new($code)->args('0')->start->wait_stop();
557564
is($p->read_all_stdout(), "0$/", '2) False scalar value was given as args.');
558565

559-
$p = Mojo::IOLoop::ReadWriteProcess->new($code, args => [(0..3)] )->start->wait_stop();
566+
$p = Mojo::IOLoop::ReadWriteProcess->new($code, args => [(0 .. 3)])
567+
->start->wait_stop();
560568
is($p->read_all_stdout(), "0$/1$/2$/3$/", '1) Args given as arrayref.');
561569

562-
$p = Mojo::IOLoop::ReadWriteProcess->new($code)->args([(0..3)])->start->wait_stop();
570+
$p = Mojo::IOLoop::ReadWriteProcess->new($code)->args([(0 .. 3)])
571+
->start->wait_stop();
563572
is($p->read_all_stdout(), "0$/1$/2$/3$/", '2) Args given as arrayref.');
564573
};
565574

566575
subtest 'process in process' => sub {
567-
my $p = process(sub {
568-
is( process(execute => '/usr/bin/true')->quirkiness(1)->start()->wait_stop()->exit_status(), 0, 'process(execute) from process(code) -- retval check true');
569-
is( process(execute => '/usr/bin/false')->quirkiness(1)->start()->wait_stop()->exit_status(), 1, 'process(execute) from process(code) -- retval check false');
570-
is( process(sub { print 'sub-sub-process'})->start()->wait_stop()->read_all_stdout, 'sub-sub-process', 'process(code) works from process(code)');
571-
print 'DONE';
576+
my $p = process(
577+
sub {
578+
is(
579+
process(execute => '/usr/bin/true')->quirkiness(1)->start()
580+
->wait_stop()->exit_status(),
581+
0,
582+
'process(execute) from process(code) -- retval check true'
583+
);
584+
is(
585+
process(execute => '/usr/bin/false')->quirkiness(1)->start()
586+
->wait_stop()->exit_status(),
587+
1,
588+
'process(execute) from process(code) -- retval check false'
589+
);
590+
is(
591+
process(sub { print 'sub-sub-process' })->start()->wait_stop()
592+
->read_all_stdout,
593+
'sub-sub-process',
594+
'process(code) works from process(code)'
595+
);
596+
print 'DONE';
572597
})->start()->wait_stop();
573598

574-
is ($p->read_all_stdout(), 'DONE', "Use ReadWriteProcess inside of ReadWriteProcess(code=>'')");
599+
is($p->read_all_stdout(), 'DONE',
600+
"Use ReadWriteProcess inside of ReadWriteProcess(code=>'')");
575601
};
576602

577603
subtest 'execute exeption handling' => sub {
578-
throws_ok {
579-
process(execute => '/I/do/not/exist')->start()->wait_stop()->exit_status();
580-
} qr%/I/do/not/exist%, 'Execute throw exception, if executable does not exists';
581-
582-
my $p = process(execute => 'sleep 0.2')->start();
583-
attempt {
584-
attempts => 20,
585-
condition => sub { defined($p->exit_status)},
586-
};
587-
is ($p->is_running(), 0, 'Process not running');
588-
is ($p->exit_status(), 0, 'Exit status is 0');
604+
throws_ok {
605+
process(execute => '/I/do/not/exist')->start()->wait_stop()->exit_status();
606+
}
607+
qr%/I/do/not/exist%, 'Execute throw exception, if executable does not exists';
608+
609+
my $p = process(execute => 'sleep 0.2')->start();
610+
attempt {attempts => 20, condition => sub { defined($p->exit_status) },};
611+
is($p->is_running(), 0, 'Process not running');
612+
is($p->exit_status(), 0, 'Exit status is 0');
589613
};
590614

591615
done_testing;

0 commit comments

Comments
 (0)