Commit 9fe44d83 authored by Peter Pentchev's avatar Peter Pentchev

p6: make the prototypes a bit more stringent.

Add the :D constraint where appropriate.
Make the usage() function error out by default.
parent 67c26a91
......@@ -19,7 +19,7 @@ sub version()
say 'ethstats 1.1.1';
}
sub usage(Bool $err)
sub usage(Bool:D $err = True)
{
my $s = q:to/EOUSAGE/;
Usage: ethstats [-t] [-C | -M] [-c count] [-i iface] [-n period]
......@@ -48,7 +48,7 @@ sub reset_totals()
%total = ( :kb({}), :packets({}) );
}
sub update_traffic(%dev, %odev, UInt $period)
sub update_traffic(%dev, %odev, UInt:D $period)
{
for %dev.keys -> $what {
for %dev{$what}.keys -> $dir {
......@@ -130,7 +130,7 @@ class InterfaceActions {
method uint($/) { $/.make: $/.UInt }
}
sub convert(Str $iface, UInt $period)
sub convert(Str $iface, UInt:D $period)
{
try my $f = open :r, '/proc/net/dev', :chomp(False), :enc('latin1');
die "Could not open the interface info pseudo-file: $!" if $!;
......@@ -163,12 +163,12 @@ sub convert(Str $iface, UInt $period)
return %devs;
}
sub acolor(Str $name)
sub acolor(Str:D $name)
{
return $use_color?? color($name)!! '';
}
sub format_line(Str $name, %dev)
sub format_line(Str:D $name, %dev)
{
return ($name eq 'total'?? 'total: '!! sprintf(' %6s: ', $name)) ~
sprintf('%7.2f Mb/s In %7.2f Mb/s Out - ' ~
......@@ -191,7 +191,7 @@ sub format_line(Str $name, %dev)
$opts.int('n', Nil, -> $v {
if $v < 1 {
note 'The period must be a positive integer';
usage True;
usage;
}
$period = $v;
});
......@@ -200,7 +200,7 @@ sub format_line(Str $name, %dev)
$opts.int('c', Nil, -> $v {
if $v < 1 {
note 'The count must be a positive integer';
usage True;
usage;
}
$count = $v;
});
......@@ -212,7 +212,7 @@ sub format_line(Str $name, %dev)
$opts.bool('C', Nil, -> $v {
if %flags<M> {
note 'The -C and -M options are mutually exclusive';
usage True;
usage;
}
%flags<C> = True;
$use_color = True;
......@@ -220,7 +220,7 @@ sub format_line(Str $name, %dev)
$opts.bool('M', Nil, -> $v {
if %flags<C> {
note 'The -C and -M options are mutually exclusive';
usage True;
usage;
}
%flags<M> = True;
$use_color = False;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment