There's more than one way to do things PerlMonks

### Re^4: Idea: Moose Mutal Coercion

by educated_foo (Vicar)
 on Feb 15, 2012 at 13:58 UTC ( #953954=note: print w/ replies, xml ) Need Help??

in reply to Re^3: Idea: Moose Mutal Coercion
in thread Idea: Moose Mutual Coercion

A less-distracting example might be a ball with mass, velocity, and momentum (calculate the third given two). I still think reaching for a lazy-building pile of Moose goop is wrong, since it's way easier to just have a cache:

```sub momentum {
my \$self = shift;
\$self->{momentum} //= \$self->{mass} * \$self->{velocity};
}
but at least this may let people focus on the idea.

Comment on Re^4: Idea: Moose Mutal Coercion
Replies are listed 'Best First'.
Re^5: Idea: Moose Mutal Coercion
by BrowserUk (Pope) on Feb 15, 2012 at 14:31 UTC

You think that the OP is suggesting that Moose herders use his module so that they can type this:

```package Equation_Problem;
use Moose;
use MooseX::Invertible_Build;

has mass     => ( isa => Num);
has velocity => ( isa => Num);
has momentum => (
isa => Num,
invertible_build => {
A => 'mass',
B => 'velocity',
via => 'A * B',
},
);

To 'save' typing:

```package Equation_Problem;
use Moose;

has mass     => ( isa => Num);
has velocity => ( isa => Num);

sub momentum {
my \$self = shift;
\$self->mass * \$self->velocity;
}

Hm. It can't be that in(s)ane.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

No. I guess the OP wants a class which you can initialize with any two attributes, but you can then ask for all three.

Ah! The hackers are gonna love this:

```package Hash::PassPhrase;
use Moose;
use MooseX::Invertible_Build;

has passPhrase    => ( isa => Str );
has salt          => ( isa => Str );
has hash => (
isa => Str,
invertible_build => {
A => 'salt',
B => 'passPhrase',
via => 'crypt( A, B )',
},
);

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Create A New User
Node Status?
node history
Node Type: note [id://953954]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2015-08-31 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?