in reply to Class::MethodMaker, workplace politics, and patches

Yeah,yeah. I know. I suck!

#! perl -slw use strict; use Data::Dumper; package Foo; sub new { bless {}, $_[ 0 ] } package MyClass; use Class::MethodMaker [ scalar => [ { -type => 'Foo', -default_ctor => 'new' }, 'foo', ], ]; sub new { my $class = shift; bless {}, $class; } if( @ARGV and $Class::MethodMaker::VERSION eq '2.05' ) { no warnings 'redefine'; *MyClass::foo_isset = sub : method { package Class::MethodMaker::scalar; exists( $_[0]{foo} ); } } package main; my $m = MyClass->new; print $m->foo; $m->foo_reset; print $m->foo_isset ? 'foo is set' : 'foo is not set'; __END__ [19:57:31.35] P:\test>430184 Foo=HASH(0x225000) foo is set [19:57:33.20] P:\test>430184 patchit Foo=HASH(0x225000) foo is not set

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
  • Comment on Re: Class::MethodMaker, workplace politics, and patches (A dynamic patch)
  • Download Code

Replies are listed 'Best First'.
Re^2: Class::MethodMaker, workplace politics, and patches (A dynamic patch)
by dragonchild (Archbishop) on Feb 11, 2005 at 20:17 UTC
    Thank you! This is exactly what I was looking for! :-)

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re^2: Class::MethodMaker, workplace politics, and patches (A dynamic patch)
by fluffy (Scribe) on Mar 13, 2005 at 12:29 UTC
    Morning,

    Sorry to be late to the party. BrowserUk, your answer is quite right; but you can make it slightly easier on yourself by simply defining foo_isset in the class before Class::MethodMaker(->import) is called. It will never overwrite an existing method. Since the example does a use, that would need to be in a BEGIN{} ahead of the use.

    Mx.