{"id":180,"date":"2013-08-22T22:32:00","date_gmt":"2013-08-22T22:32:00","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/Hayek\/Jochen\/wp\/blog-en\/2013\/08\/22\/brian-d-foys-book-mastering-perl-new-to-modules-as-programs-aka-modulinos\/"},"modified":"2013-08-22T22:32:00","modified_gmt":"2013-08-22T22:32:00","slug":"brian-d-foys-book-mastering-perl-new-to-modules-as-programs-aka-modulinos","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2013\/08\/22\/brian-d-foys-book-mastering-perl-new-to-modules-as-programs-aka-modulinos\/","title":{"rendered":"brian d foy&#8217;s book &#8220;Mastering Perl&#8221;: New to \u201cModules as Programs\u201d (AKA Modulinos)"},"content":{"rendered":"<p>\t\t\t\tIn the end you will find a [<a href=\"http:\/\/chimera.labs.oreilly.com\/books\/1234000001527\/ch18.html\">link<\/a>] to the entire new respective chapter.<\/p>\n<p><a href=\"http:\/\/www.masteringperl.org\/2013\/08\/new-to-modules-as-programs\/\">New to \u201cModules as Programs\u201d<\/a>: <br \/>\nI (that refers to <a href=\"http:\/\/en.wikipedia.org\/wiki\/brian_d_foy\">brian foy<\/a>) keep wanting to name this chapter \u201cModulinos\u201d, but that doesn\u2019t mean much to someone who doesn\u2019t have that idea yet, so I leave it as is. <br \/>\nFor awhile, I\u2019ve wanted to reduce the modulino idea to a single statement, perhaps a <code>use<\/code> statement:<\/p>\n<pre>use Modulino;<\/pre>\n<p>I think I\u2019ve got most of the way there with <a href=\"http:\/\/www.metacpan.org\/module\/Modulino::Base\">Modulino::Base<\/a>, which I\u2019ve included in my update to the chapter. It was an interesting journey though. I didn\u2019t want to inherit from it because it\u2019s not really that sort of relationship. I could add it as a role or trait, but I didn\u2019t want to deal with complication surrounding that. I settled on a <code>require<\/code> because the code needs to run after the compile phase when all of the methods are already compiled. That was true of the code that was already controlling that behavior:<\/p>\n<pre>__PACKAGE__-&gt;run(@ARGV) unless caller;<\/pre>\n<p>Moving all of the code into another file (and using subroutines) messed with <code>caller<\/code> a bit. Now I had to look back a couple of levels to see what was going on. That seems simple now that I\u2019ve figured it out, but on the way I loaded <a href=\"http:\/\/www.metacpan.org\/module\/Modulino::Base\">Modulino::Base<\/a> in many ways and looked at <code>caller<\/code> going two levels back to convince myself I was doing the right thing. As with most coding problems, the other weird things I was trying to do had clouded the problems and simplifying the module solved it.<\/p>\n<div>\n<div>\n<img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.masteringperl.org\/wp-content\/uploads\/2013\/08\/modulino_spreadsheet.png?w=500\" ><\/div>\n<\/div>\n<p>The danger with any code written specifically for a book is that it hasn\u2019t been used widely and its problems haven\u2019t appeared. I know they are there. Not only that, once the book is done, the author tends to stop supporting the code. I certainly plan that because I think the idea is simple enough that no one should use a module for it. That is, no one should create an external dependency to get something so simple.<br \/>\nI\u2019ve also expanded the modulino idea. Previously, it was about running as a program or loading as a module. However, we can do other things based on any condition. The module can run as a test script. <a href=\"http:\/\/www.metacpan.org\/module\/Modulino::Base\">Modulino::Base<\/a> looks for methods that start with <code>_test_<\/code> and runs them as subtests if <code>CPANTEST<\/code> is set to a true value. I stole that idea from Python, although it doesn\u2019t seem to be as popular as it was when I learned that language. <br \/>\nBeyond that, I experimented with having a module file be a template for its own documentation. Using some switch to say I wanted to read the docs, it ran <a href=\"http:\/\/www.metacpan.org\/module\/Pod::Perldoc\">Pod::Perldoc<\/a> on itself, making modifications to the Pod along the way, such as automatically inserting the right package name. I like that idea and I think there\u2019s more behind it, but it\u2019s not something I want to delay the book for.<br \/>\nYou can check out <a href=\"http:\/\/chimera.labs.oreilly.com\/books\/1234000001527\/ch18.html\">this chapter<\/a> in O\u2019Reilly Atlas.\t\t\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the end you will find a [link] to the entire new respective chapter. New to \u201cModules as Programs\u201d: I (that refers to brian foy) keep wanting to name this chapter \u201cModulinos\u201d, but that doesn\u2019t mean much to someone who doesn\u2019t have that idea yet, so I leave it as is. For awhile, I\u2019ve wanted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[666],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-2U","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":0,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}