{"id":204,"date":"2011-09-13T20:29:46","date_gmt":"2011-09-13T19:29:46","guid":{"rendered":"http:\/\/blog.briang.org\/?p=204"},"modified":"2014-01-25T13:58:59","modified_gmt":"2014-01-25T13:58:59","slug":"moose-tips","status":"publish","type":"post","link":"https:\/\/blog.briang.org\/?p=204","title":{"rendered":"Moose tips"},"content":{"rendered":"<h2>init_arg &#8211; use alternate attribute name in new()<\/h2>\n<pre class=\"brush:perl\">\r\n# in package Foo\r\nhas qw(bar is ro init_arg quux);\r\n...\r\n# elsewhere\r\nmy $foo = Foo->new( quux => 1 );\r\n<\/pre>\n<p>Foo has an attribute named &#8220;bar&#8221;, but we pass &#8220;quux&#8221; to the constructor.<P><\/p>\n<p>See <a href=\"http:\/\/search.cpan.org\/~doy\/Moose-2.0205\/lib\/Moose\/Manual\/Attributes.pod#Constructor_parameters_(init_arg)\">Moose::Manual::Attributes \/ Constructor parameters (init_arg)<\/a><\/p>\n<h2>init_arg &#8211; ban setting an attribute in new()<\/h2>\n<pre class=\"brush:perl\">\r\n# in package Foo\r\nhas qw(bar is ro), init_arg => undef;\r\n...\r\n# elsewhere\r\nmy $foo = Foo->new( bar => 1 ); # dies\r\n<\/pre>\n<p>See <a href=\"http:\/\/search.cpan.org\/~doy\/Moose-2.0205\/lib\/Moose\/Manual\/Attributes.pod#Constructor_parameters_(init_arg)\">Moose::Manual::Attributes \/ Constructor parameters (init_arg)<\/a><\/p>\n<h2>lazy_build<\/h2>\n<pre class=\"brush:perl\">\r\n# in package Foo\r\nhas qw(bar is ro isa ArrayRef lazy_build 1);\r\n# gets me:\r\n#   lazy      => 1\r\n#   builder   => '_build_bar',\r\n#   clearer   => 'clear_bar',\r\n#   predicate => 'has_bar',\r\n...\r\nsub _build_bar {\r\n    my ($self, @args) = @_;\r\n    ...\r\n    return [ reverse @args ];\r\n}\r\n<\/pre>\n<p>See <a href=\"http:\/\/search.cpan.org\/~doy\/Moose-2.0205\/lib\/Moose\/Meta\/Attribute.pm\">Moose::Meta::Attribute<\/a><\/p>\n<h2>Native traits<\/h2>\n<h3>Array<\/h3>\n<ul>\n<li>accessor($index)\n<li>accessor($index, $value)\n<li>clear\n<li>count\n<li>delete($index)\n<li>elements\n<li>first( sub { &#8230; } )\n<li>first_index( sub { &#8230; } )\n<li>get($index)\n<li>grep( sub { &#8230; } )\n<li>insert($index, $value)\n<li>is_empty\n<li>join($str)\n<li>map( sub { &#8230; } )\n<li>natatime($n)\n<li>natatime($n, $code)\n<li>pop\n<li>push($value, &#8230;)\n<li>reduce( sub { &#8230; } )\n<li>set($index, $value)\n<li>shallow_clone\n<li>shift\n<li>shuffle\n<li>sort( sub { &#8230; } )\n<li>sort\n<li>sort_in_place( sub { &#8230; } )\n<li>sort_in_place\n<li>splice($offs, $len, @values)\n<li>uniq\n<li>unshift($value, &#8230;)\n<\/ul>\n<h3>Bool<\/h3>\n<h3>Code<\/h3>\n<h3>Counter<\/h3>\n<h3>Has<\/h3>\n<h3>Number<\/h3>\n<h3>String<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>init_arg &#8211; use alternate attribute name in new() # in package Foo has qw(bar is ro init_arg quux); &#8230; # elsewhere my $foo = Foo->new( quux => 1 ); Foo has an attribute named &#8220;bar&#8221;, but we pass &#8220;quux&#8221; to the constructor. See Moose::Manual::Attributes \/ Constructor parameters (init_arg) init_arg &#8211; ban setting an attribute in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,56,5,53,49],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-briang","tag-cpanmoose","tag-perl","tag-tips","tag-todo"],"_links":{"self":[{"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.briang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":10,"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/blog.briang.org\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/237"}],"wp:attachment":[{"href":"https:\/\/blog.briang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.briang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.briang.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}