A picky caller
I have got myself a paradoxical harddrive by combining a fast ssd and a sizeable disk by setting up a a bcache on my linux box. Now I got a harddrive that is really fast with small files. There are a few stats bcache is providing via sysfs. To watch them one requires to read a few text files. A well suited task for slurp
. I ended up with a bunch of pointy blocks that look like this:
-> $cache {
slurp("/sys/fs/bcache/$cache/cache_available_percent").chomp ~ '%'
}
I put them together with a name into an Array to be able to loop over them. As it turned out there are two groups of pointies. The one group needs the name of the bcache-block device which holds the actualy filesystem. The other group gets the UUID of the cache group. I need to group the output of the two groups so I get:
bcache0:
dirty data: 36.0k
ebc67019-9d50-4042-8080-b173e2ba802f:
hit ratio: 62% 66% 50% 0%
bypassed: 7.0G 2.4G 65.1M 9.1M
cache available: 94%
I could have split up the array but figured that I can check the signature of the pointy instead to select what is being output.
for bcache-devs() -> $dev {
with $dev {
say BOLD $dev, ':';
for @stats -> $name, &f {
next unless &f.signature.params».name eq '$dev';
put "\t", $name, ': ', .&f
}
}
}
If the name of the positional doesn’t fit I just skip the output.
Next I tried to match the signature by adding subsets of Str
to the signature of the pointes. Sadly matching a signature literal like so doesn’t work in this case.
subset Dev of Str;
say 'match' if &f.signature ~~ :(Dev $dev);
If I would define my one classes that would certainly work. It seems the sloppy matching of subsets is working as intended. A bit of a shame because subsets are so easy to set up. For my example just matching the parameter name is fine because it saves time when typing the pointies.
Nonetheless it’s really neat that the caller can has a say if it likes the signature of the callee in Perl 6.
-
January 28, 2019 at 15:562019.04 Summer of Code! | Weekly changes in and around Perl 6