summaryrefslogtreecommitdiff
path: root/_posts/2009-06-30-private-and-protected-methods-with-moose.md
diff options
context:
space:
mode:
authorFranck Cuny <franckcuny@gmail.com>2016-07-02 20:04:59 -0700
committerFranck Cuny <franckcuny@gmail.com>2016-07-02 20:04:59 -0700
commit8f187c573954b6c8d1650ac33a164c52e032ac16 (patch)
treec605d0cf51d272393006e5486bfdc24984cf801f /_posts/2009-06-30-private-and-protected-methods-with-moose.md
parentUpdate some posts to make the tests pass. (diff)
downloadlumberjaph-8f187c573954b6c8d1650ac33a164c52e032ac16.tar.gz
Stop using Jekyll.
Moving away from Jekyll to Hugo. This commit clean up the old files to prepare for the migration.
Diffstat (limited to '_posts/2009-06-30-private-and-protected-methods-with-moose.md')
-rw-r--r--_posts/2009-06-30-private-and-protected-methods-with-moose.md47
1 files changed, 0 insertions, 47 deletions
diff --git a/_posts/2009-06-30-private-and-protected-methods-with-moose.md b/_posts/2009-06-30-private-and-protected-methods-with-moose.md
deleted file mode 100644
index a47e8b0..0000000
--- a/_posts/2009-06-30-private-and-protected-methods-with-moose.md
+++ /dev/null
@@ -1,47 +0,0 @@
----
-layout: post
-summary: In which I show how to write dummy private methods for Moose
-title: Private and protected methods with Moose
----
-Yesterday, one of our interns asked me a question about private method in <a href="http://www.iinteractive.com/moose/">Moose</a>. I told him that for Moose as for Perl, there is no such things as private method. By convention, methods prefixed with '_' are considered private.
-
-But I was curious to see if it would be something complicated to implement in Moose. First, I've started to look at how the 'augment' keyword is done. I've then hacked Moose directly to add the private keyword. After asking advice to <a href="http://blog.woobling.org/">nothingmuch</a>, he recommended me that I implement this in a MooseX::* module instead. The result is <a href="http://git.lumberjaph.net/p5-moosex-methodprivate.git/">here</a>.
-
-From the synopsis, MooseX::MethodPrivate do:
-
-{% highlight perl %}
-package Foo;
-use MooseX::MethodPrivate;
-
-private 'foo' => sub {
-};
-
-protected 'bar' => sub {
-};
-
-
-my $foo = Foo->new;
-$foo->foo; # die, can't call foo because it's a private method
-$foo->bar; # die, can't call bar because it's a protected method
-
-package Bar;
-use MooseX::MethodPrivate;
-extends qw/Foo/;
-
-sub baz {
- my $self = shift;
- $self->foo; #die, can't call foo because it's a private method
- $self->bar; # ok, can call this method because we extends Foo and
- # it's a protected method
-}
-{% endhighlight %}
-
-I was surprised to see how easy it's to extend Moose syntax. All I've
-done was this:
-
-{% highlight perl %}
- Moose::Exporter->setup_import_methods(
- with_caller => [qw( private protected )],);
-{% endhighlight %}
-
-and write the `private` and `protected` sub. I'm sure there is some stuff I can do to improve this, but for a first test, I'm happy with the result and still amazed how easy it was to add this two keywords.