Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^4: Class::InsideOut - yet another riff on inside out objects.

by adrianh (Chancellor)
on Dec 19, 2002 at 10:52 UTC ( #221080=note: print w/replies, xml ) Need Help??

in reply to Re^3: Class::InsideOut - yet another riff on inside out objects.
in thread Class::InsideOut - yet another riff on inside out objects.

As I understand it the %hash isn't actually in scope when the ATTR handler is called, so there is no way to get at it with PadWalker...


#! /usr/bin/perl use strict; use warnings; package Foo; use Attribute::Handlers; use PadWalker qw(peek_my); use Data::Dumper; sub Field : ATTR(HASH) { my ($class, $symbol, $hash) = @_; if ($symbol eq 'LEXICAL') { my $level=0; while (eval {peek_my($level+1)} && !$@) {$level++}; print Dumper(peek_my($level)); } else { print "got %", *{$symbol}{NAME}, " from symbol table\n"; }; }; package FooBar; use base qw(Foo); my %just_to_prove_we_are_in_the_right_scope; print "about to call ATTR with \\%foo\n"; my %foo : Field; print "about to call ATTR with \\%bar\n"; my %bar : Field;


about to call ATTR with \%foo $VAR1 = { '%just_to_prove_we_are_in_the_right_scope' => {} }; about to call ATTR with \%bar $VAR1 = { '%just_to_prove_we_are_in_the_right_scope' => {}, '%foo' => {} };

Unless I'm missing something (entirely possible) I don't see how Devel::Caller can help here? There isn't a way that (in the above example) you can get at the name 'foo' at the time the %foo hash reference is passed to the ATTR handler.

Replies are listed 'Best First'.
Re^5: Class::InsideOut - yet another riff on inside out objects.
by Aristotle (Chancellor) on Dec 19, 2002 at 14:16 UTC
    $VAR1 = { '%bar' => {}, '%just_to_prove_we_are_in_the_right_scope' => {}, '%foo' => {} }; $VAR1 = { '%bar' => {}, '%just_to_prove_we_are_in_the_right_scope' => {}, '%foo' => {} }; about to call ATTR with \%foo about to call ATTR with \%bar
    Perl 5.6.1, PadWalker 0.08, Attribute::Handlers 0.78

    Makeshifts last the longest.

      Ah ha! - from perldelta for perl 5.8.0

      The "my EXPR : ATTRS" syntax now applies variable attributes at run-time. (Subroutine and "our" variables still get attributes applied at compile-time.) See attributes for additional details. In particular, how- ever, this allows variable attributes to be useful for "tie" interfaces, which was a deficiency of earlier releases.

      Hmmm... I'm getting my behaviour under perl = 5.008 , Attribute::Handlers = 0.78 , PadWalker = 0.08 ,

      Off to go look at the module dependencies. I'll be so happy if I can make it work without that source filter :-)

        I'm myself working on an altered rendition of the Class::InsideOut package that might remedy the current problems.. not sure if what I have in mind will work out, of course.

        Makeshifts last the longest.

Re^5: Class::InsideOut - yet another riff on inside out objects.
by diotalevi (Canon) on Dec 19, 2002 at 12:28 UTC

    Oh ok. I was expressing more of a generalized ability so I might combine that with a search of all the contexts I could find on the symbol table as well. Very slow, not the right approach but still doable. So that'd just have to go all around and collect the pads from every visible code reference and I'm thinking that eventually you hit the right one...

    Fun Fun Fun in the Fluffy Chair

      Darn. I hoped there was something obvious I was missing :-)

      While scanning all coderefs & symbol table entries might work for a lot of cases, I don't think it is completely general. For example, consider:

      { package Foo; use base qw(Class::InsideOut); sub new { return bless [], shift }; { my %foo : Field }; };

      There are no subroutines that have %foo in their scope so, without generating code with a source filter, I can see no way of getting access to the pad with "%foo" in it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://221080]
[Discipulus]: and it's GPIO how are seen by the OS? Perl can speak thougth them?
[marto]: yes
[Discipulus]: thanks i definetively must learn such stuff.. i must come out with a killing product and after i'll just do Perl elctronic and music.. ;=)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2017-10-17 09:55 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (225 votes). Check out past polls.