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() ...@@ -19,7 +19,7 @@ sub version()
say 'ethstats 1.1.1'; say 'ethstats 1.1.1';
} }
sub usage(Bool $err) sub usage(Bool:D $err = True)
{ {
my $s = q:to/EOUSAGE/; my $s = q:to/EOUSAGE/;
Usage: ethstats [-t] [-C | -M] [-c count] [-i iface] [-n period] Usage: ethstats [-t] [-C | -M] [-c count] [-i iface] [-n period]
...@@ -48,7 +48,7 @@ sub reset_totals() ...@@ -48,7 +48,7 @@ sub reset_totals()
%total = ( :kb({}), :packets({}) ); %total = ( :kb({}), :packets({}) );
} }
sub update_traffic(%dev, %odev, UInt $period) sub update_traffic(%dev, %odev, UInt:D $period)
{ {
for %dev.keys -> $what { for %dev.keys -> $what {
for %dev{$what}.keys -> $dir { for %dev{$what}.keys -> $dir {
...@@ -130,7 +130,7 @@ class InterfaceActions { ...@@ -130,7 +130,7 @@ class InterfaceActions {
method uint($/) { $/.make: $/.UInt } 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'); try my $f = open :r, '/proc/net/dev', :chomp(False), :enc('latin1');
die "Could not open the interface info pseudo-file: $!" if $!; die "Could not open the interface info pseudo-file: $!" if $!;
...@@ -163,12 +163,12 @@ sub convert(Str $iface, UInt $period) ...@@ -163,12 +163,12 @@ sub convert(Str $iface, UInt $period)
return %devs; return %devs;
} }
sub acolor(Str $name) sub acolor(Str:D $name)
{ {
return $use_color?? color($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)) ~ return ($name eq 'total'?? 'total: '!! sprintf(' %6s: ', $name)) ~
sprintf('%7.2f Mb/s In %7.2f Mb/s Out - ' ~ sprintf('%7.2f Mb/s In %7.2f Mb/s Out - ' ~
...@@ -191,7 +191,7 @@ sub format_line(Str $name, %dev) ...@@ -191,7 +191,7 @@ sub format_line(Str $name, %dev)
$opts.int('n', Nil, -> $v { $opts.int('n', Nil, -> $v {
if $v < 1 { if $v < 1 {
note 'The period must be a positive integer'; note 'The period must be a positive integer';
usage True; usage;
} }
$period = $v; $period = $v;
}); });
...@@ -200,7 +200,7 @@ sub format_line(Str $name, %dev) ...@@ -200,7 +200,7 @@ sub format_line(Str $name, %dev)
$opts.int('c', Nil, -> $v { $opts.int('c', Nil, -> $v {
if $v < 1 { if $v < 1 {
note 'The count must be a positive integer'; note 'The count must be a positive integer';
usage True; usage;
} }
$count = $v; $count = $v;
}); });
...@@ -212,7 +212,7 @@ sub format_line(Str $name, %dev) ...@@ -212,7 +212,7 @@ sub format_line(Str $name, %dev)
$opts.bool('C', Nil, -> $v { $opts.bool('C', Nil, -> $v {
if %flags<M> { if %flags<M> {
note 'The -C and -M options are mutually exclusive'; note 'The -C and -M options are mutually exclusive';
usage True; usage;
} }
%flags<C> = True; %flags<C> = True;
$use_color = True; $use_color = True;
...@@ -220,7 +220,7 @@ sub format_line(Str $name, %dev) ...@@ -220,7 +220,7 @@ sub format_line(Str $name, %dev)
$opts.bool('M', Nil, -> $v { $opts.bool('M', Nil, -> $v {
if %flags<C> { if %flags<C> {
note 'The -C and -M options are mutually exclusive'; note 'The -C and -M options are mutually exclusive';
usage True; usage;
} }
%flags<M> = True; %flags<M> = True;
$use_color = False; $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