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.

3 Comments

Hey Aaron,

"unit class" (and "unit module" and such) just means you don't have to put { ... } around the rest of the file.

The reason that IO::Handle and other things in the Core Setting are allowed to be my-scoped is that the user program is actually treated as an *inner* scope to the Core Setting. That's why lexical things inside the Core Setting are available to user code. Your module on the other hand has to be imported.

Hope that clears something up!
- timotimo

Speaking of your Editor, that should also help deal with pod in between things; just fold them away until you need to see the pod comments :)

Leave a comment

About Aaron Baugher

user-pic I'm a programmer and Unix sysadmin who uses Perl as much as possible, operating from the Midwest USA. To hire me for sysadmin or programming work, contact me at aaron.baugher @ gmail.com or as 'abaugher' on #perl6.