{"id":461,"date":"2010-12-06T23:35:32","date_gmt":"2010-12-06T22:35:32","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/"},"modified":"2010-12-06T23:35:32","modified_gmt":"2010-12-06T22:35:32","slug":"facter-ported-to-perl-6","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/","title":{"rendered":"Facter ported to Perl 6"},"content":{"rendered":"<p>A few days ago I <a href=\"http:\/\/my.opera.com\/cstrep\/blog\/2010\/11\/28\/porting-facter-from-ruby-to-perl6\" rel=\"nofollow\">wrote about my fun experiment<\/a> trying to port <a href=\"http:\/\/projects.puppetlabs.com\/projects\/facter\" rel=\"nofollow\">facter<\/a> to <a href=\"http:\/\/www.rakudo.org\" rel=\"nofollow\">rakudo Perl 6<\/a>. I said it was &quot;almost completely functional&quot;.<\/p>\n<p>Well, I was a bit optimistic, it seems :) It took me a few more nights of hacking, but in the end <b>now it&#39;s almost completely functional<\/b> :) It basically runs, I have ported a few facts from Facter&#39;s original ruby code too, like the <a href=\"https:\/\/github.com\/puppetlabs\/facter\/blob\/master\/lib\/facter\/kernel.rb\" rel=\"nofollow\">kernel fact<\/a>, or the <a href=\"https:\/\/github.com\/puppetlabs\/facter\/blob\/master\/lib\/facter\/physicalprocessorcount.rb\" rel=\"nofollow\">physicalprocessorcount fact<\/a> and other simple ones.<\/p>\n<p>What&#39;s missing to declare the experiment successful is the implementation of <b>confines<\/b>. A confine in facter speak it&#39;s a specific restriction that applies to a fact. For example, the <b>physicalprocessorcount<\/b> fact reads some files from <code>\/proc<\/code>, and that is only available on Linux. So, in this case, the confine rule for physicalprocessorcount is that the fact kernel must have &quot;Linux&quot; as its value. In code that becomes:<\/p>\n<p><code><\/p>\n<pre>\r\nFacter.add(&quot;physicalprocessorcount&quot;, sub ($f) {\r\n    $f.confine(&quot;kernel&quot; =&gt; &quot;Linux&quot;);\r\n    $f.setcode(block =&gt; sub {\r\n        Facter::Util::Resolution.exec(&#39;grep &quot;physical id&quot; \/proc\/cpuinfo|cut -d: -f 2|sort -u|wc -l&#39;);\r\n    });\r\n});\r\n<\/pre>\n<p><\/code><\/p>\n<p>which is pretty similar to the Ruby counterpart:<\/p>\n<p><code><\/p>\n<pre>\r\nFacter.add(&quot;physicalprocessorcount&quot;) do\r\n    confine :kernel =&gt; :linux\r\n\r\n    setcode do\r\n        ppcount = Facter::Util::Resolution.exec(&#39;grep &quot;physical id&quot; \/proc\/cpuinfo|cut -d: -f 2|sort -u|wc -l&#39;)\r\n    end\r\nend\r\n<\/pre>\n<p><\/code><\/p>\n<p>The Ruby version is still more elegant, but all in all I&#39;m very happy with the outcome so far. It could probably be improved a lot too. Perl 6 is awesome. Get the code from <a href=\"http:\/\/github.com\/cosimo\/perl6-facter\/\" rel=\"nofollow\">http:\/\/github.com\/cosimo\/perl6-facter\/<\/a> and feel free to ping me or comment if you want to know more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I wrote about my fun experiment trying to port facter to rakudo Perl 6. I said it was &quot;almost completely functional&quot;. Well, I was a bit optimistic, it seems :) It took me a few more nights of hacking, but in the end now it&#39;s almost completely functional :) It basically [&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,148,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>Facter ported to Perl 6 - 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\/12\/facter-ported-to-perl-6\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Facter ported to Perl 6 - Random hacking\" \/>\n<meta property=\"og:description\" content=\"A few days ago I wrote about my fun experiment trying to port facter to rakudo Perl 6. I said it was &quot;almost completely functional&quot;. Well, I was a bit optimistic, it seems :) It took me a few more nights of hacking, but in the end now it&#039;s almost completely functional :) It basically [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-06T22:35:32+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=\"1 minute\" \/>\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\/12\/facter-ported-to-perl-6\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"Facter ported to Perl 6\",\"datePublished\":\"2010-12-06T22:35:32+00:00\",\"dateModified\":\"2010-12-06T22:35:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\"},\"wordCount\":218,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"development\",\"facter\",\"fun\",\"languages\",\"perl\",\"perl6\",\"puppet\",\"ruby\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\",\"name\":\"Facter ported to Perl 6 - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2010-12-06T22:35:32+00:00\",\"dateModified\":\"2010-12-06T22:35:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Facter ported to Perl 6\"}]},{\"@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":"Facter ported to Perl 6 - 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\/12\/facter-ported-to-perl-6\/","og_locale":"en_US","og_type":"article","og_title":"Facter ported to Perl 6 - Random hacking","og_description":"A few days ago I wrote about my fun experiment trying to port facter to rakudo Perl 6. I said it was &quot;almost completely functional&quot;. Well, I was a bit optimistic, it seems :) It took me a few more nights of hacking, but in the end now it&#39;s almost completely functional :) It basically [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/","og_site_name":"Random hacking","article_published_time":"2010-12-06T22:35:32+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"Facter ported to Perl 6","datePublished":"2010-12-06T22:35:32+00:00","dateModified":"2010-12-06T22:35:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/"},"wordCount":218,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["development","facter","fun","languages","perl","perl6","puppet","ruby"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/","name":"Facter ported to Perl 6 - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2010-12-06T22:35:32+00:00","dateModified":"2010-12-06T22:35:32+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/12\/facter-ported-to-perl-6\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"Facter ported to Perl 6"}]},{"@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\/461"}],"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=461"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/461\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}