My First Perl 6 Module: Net::SSH

来源:转载


I've written my first Perl 6 module! I wanted to start contributing modules, but it took a while to find one that wasn't already done, but was simple enough to tackle as my first one. I also wanted to make a proper distribution for it, which was something I hadn't done before even in Perl 5, so it took a while to get everything in order. I'm sure there are still mistakes, but I'm still working on it, and it should go much better on future modules.

The distribution is at my GitLab repository. So far, it's just a simple wrapper around the 'ssh' command-line tool, which runs a command on a remote server and returns the output as an array of lines. I borrowed some of the code from the Perl 5 module Net::SSH, and Perl 6-ified it. It's not ready for panda or anything, but I hope to get it there once I make it more capable and add more error-checking and testing. A few observations:

I don't completely understand the module/class/package distinctions yet. I ended up with a class because I needed a few attributes. I guess a module is just a package of functions. And a package....not sure. I also had to make it a 'unit class', and I'm not sure why. I started out with ' my class Net::SSH {', but that wouldn't work at all, I think because it made the class private to the file. I got that idea from looking at some of the core modules like IO::Handle, and it seems to work there, so I'm not sure why. Some research to do on those things.

I put all my POD at the end of the file, because the ' =begin pod' lines seem to confuse cperl-mode's syntax highlighting in emacs. Not surprising, since I think it's a fairly new change. I should go put an issue in for the maintainer of cperl-mode when I'm done writing this. Anyway, I originally had the POD sprinkled through the file next to the class and method definitions, but I don't know if I like that anyway -- more scrolling to get to different pieces of code. My preference would probably be to put the POD in a different file altogether, but I want to follow whatever standard there is.

As always, suggestions, corrections, and laughter are welcome.



分享给朋友:
您可能感兴趣的文章:
随机阅读: