On 25/02/11 20:54, Markus Roberts wrote:
> B --
> 
> 
>     Thanks for the example. This is quite interesting and opens the door to
>     a lot of strange things :)
> 
> 
> Yes it does.  Be sure to have a big stick handy when you open that door.  :)
>  
> 
>     I was thinking about allowing the user to describe probes by specifying
>     a puppet class and a method through an indirection to control probes
>     (like in "Puppet::Indirector::Indirection.find"), then I'd do something
>     (completely untested):
> 
>     method = "find"
>     klass_name = "Puppet::Indirector::Indirection"
>     require klass_name.split('::').map { |n| n.downcase }.join('/')
> 
>     klass = klass_name.split('::').inject(Puppet) { |p,c| p.const_get(c) }
>     klass.class_eval do
>      alias "instr_#{method}" method
>      define_method(method, *args) do
>        # here call to instrumentation
>        send("instr_#{method}", args)
>      ensure
>       # here wrap up instrumentation
>      end
>     end
> 
>     Then I hope, somewhere else, someone calling Puppet::Something.find
>     (provided Something uses the indirector of course), then it would call
>     my programmatic redifinition of "find"...
> 
> 
> Yikes.
>  
> 
>     This will be a funny week-end if that proves to work :)
> 
> 
> Yeah, it will.  A few thoughts:
> 
> 1) alias takes an identifier, not a string, so you'll have to use
> alias_method (which also needs a coma between the arguments).
> 2) you have to be careful with interpolation, in any case, as there are
> scope changes to watch out for.

Can you elaborate on this?

> 3) class_eval/define_method add quite a few wrinkles over class/def
> (which are after all executable, and can be run dynamically).

It doesn't seem possible to say:
def <code here that gives a method name>
end

So I'll have to use define_method.

I'm also concerned by the performance penalty paid when redefining a
method like this...

> Good luck, & feel free to ping me if you hit a snag.

I will certainly do :)
-- 
Brice Figureau
My Blog: http://www.masterzen.fr/

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to