{"id":463,"date":"2010-11-28T22:37:33","date_gmt":"2010-11-28T21:37:33","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/"},"modified":"2010-11-28T22:37:33","modified_gmt":"2010-11-28T21:37:33","slug":"porting-facter-from-ruby-to-perl6","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/","title":{"rendered":"Porting Facter from Ruby to Perl6"},"content":{"rendered":"<p>I&#39;ve been playing with <a href=\"http:\/\/www.puppetlabs.com\/puppet\/\" rel=\"nofollow\">Puppet<\/a> for a while now. One of the most interesting (and simple!) components of Puppet is <a href=\"http:\/\/www.puppetlabs.com\/puppet-3\/related-projects\/facter\/\" rel=\"nofollow\">Facter<\/a>.<\/p>\n<p><strong>Facter<\/strong> is a small software that reports &quot;facts&quot; about your computer. When you run facter, its output looks like the following:<\/p>\n<pre><code>architecture =&gt; x86_64\r\nfacterversion =&gt; 1.5.6\r\nfqdn =&gt; cd01.localdomain.lan\r\nhardwaremodel =&gt; x86_64\r\nhostname =&gt; cd01\r\nid =&gt; cosimo\r\ninterfaces =&gt; eth0,pan0\r\nipaddress =&gt; 10.0.0.1\r\n...\r\nuptime_hours =&gt; 422\r\nuptime_seconds =&gt; 1519256\r\nvirtual =&gt; physical<\/code><\/pre>\n<p>It is interesting also because it&#39;s extensible with your own custom plugins. A custom plugin is just a Ruby file with usually a call to <code>Facter.add<\/code>:<\/p>\n<pre><code>Facter.add(:kernel) do\r\n    setcode do\r\n        require &#39;rbconfig&#39;\r\n        case Config::CONFIG[&#39;host_os&#39;]\r\n        when \/mswin|win32|dos|cygwin|mingw\/i\r\n            &#39;windows&#39;\r\n        else\r\n            Facter::Util::Resolution.exec(&quot;uname -s&quot;)\r\n        end\r\n    end\r\nend<\/code><\/pre>\n<p>As a little experiment to become more familiar with Ruby and at the same time to enjoy writing some Perl 6, I decided to study the facter project and then port it to Perl6.<\/p>\n<p>That took me a few hours over a couple of weekends, and it&#39;s <a href=\"http:\/\/github.com\/cosimo\/perl6-facter\/\" rel=\"nofollow\">almost completely functional<\/a>. It is a straight port from the Ruby code, so it <strong>doesn&#39;t really use the magic powers of Perl6 yet<\/strong>. The idea is to use a different branch, now that I know it well under the hood, and to rewrite it from the ground up in Perl6.<\/p>\n<p>I found out that <strong>Ruby code maps very closely to Perl6<\/strong>, apart from the <code>yield<\/code> instruction and a different model for static\/instance variables. For yield, something that would be close in Perl6 is <code>gather\/take<\/code>, but I&#39;m not really sure that is the appropriate statement to use. <code>yield<\/code> is used in the fact value resolution algorithm, and that is currently the only thing that doesn&#39;t work properly in my port. Everything else is in place. Regarding static\/instance variables, Ruby uses <code>@attribute<\/code> for instance variables, and <code>@@attribute<\/code> for static variables. In Perl6, instance variables are denoted with <code>$.attribute<\/code> if public, while static variables are package globals, so you can use <code>our $attribute<\/code>.<\/p>\n<p>Of course, there&#39;s a lot more! If you&#39;re interested, take a look at the code on Github, the URL is <a href=\"http:\/\/github.com\/cosimo\/perl6-facter\" rel=\"nofollow\">http:\/\/github.com\/cosimo\/perl6-facter<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ve been playing with Puppet for a while now. One of the most interesting (and simple!) components of Puppet is Facter. Facter is a small software that reports &quot;facts&quot; about your computer. When you run facter, its output looks like the following: architecture =&gt; x86_64 facterversion =&gt; 1.5.6 fqdn =&gt; cd01.localdomain.lan hardwaremodel =&gt; x86_64 hostname [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[91,347,353,50,290,260,352],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Porting Facter from Ruby to Perl6 - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Porting Facter from Ruby to Perl6 - Random hacking\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve been playing with Puppet for a while now. One of the most interesting (and simple!) components of Puppet is Facter. Facter is a small software that reports &quot;facts&quot; about your computer. When you run facter, its output looks like the following: architecture =&gt; x86_64 facterversion =&gt; 1.5.6 fqdn =&gt; cd01.localdomain.lan hardwaremodel =&gt; x86_64 hostname [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2010-11-28T21:37:33+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"Porting Facter from Ruby to Perl6\",\"datePublished\":\"2010-11-28T21:37:33+00:00\",\"dateModified\":\"2010-11-28T21:37:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\"},\"wordCount\":309,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"development\",\"facter\",\"languages\",\"perl\",\"perl6\",\"puppet\",\"ruby\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\",\"name\":\"Porting Facter from Ruby to Perl6 - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2010-11-28T21:37:33+00:00\",\"dateModified\":\"2010-11-28T21:37:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Porting Facter from Ruby to Perl6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Porting Facter from Ruby to Perl6 - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/","og_locale":"en_US","og_type":"article","og_title":"Porting Facter from Ruby to Perl6 - Random hacking","og_description":"I&#39;ve been playing with Puppet for a while now. One of the most interesting (and simple!) components of Puppet is Facter. Facter is a small software that reports &quot;facts&quot; about your computer. When you run facter, its output looks like the following: architecture =&gt; x86_64 facterversion =&gt; 1.5.6 fqdn =&gt; cd01.localdomain.lan hardwaremodel =&gt; x86_64 hostname [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/","og_site_name":"Random hacking","article_published_time":"2010-11-28T21:37:33+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"Porting Facter from Ruby to Perl6","datePublished":"2010-11-28T21:37:33+00:00","dateModified":"2010-11-28T21:37:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/"},"wordCount":309,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["development","facter","languages","perl","perl6","puppet","ruby"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/","name":"Porting Facter from Ruby to Perl6 - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2010-11-28T21:37:33+00:00","dateModified":"2010-11-28T21:37:33+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/11\/porting-facter-from-ruby-to-perl6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"Porting Facter from Ruby to Perl6"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/463"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=463"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/463\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}