A moose around method modifier applies to several attributes, how do I tell which attribute is being modified?

Todd

Assuming a Moose object like this

package Foo;
use Moose;
has a => ( is => 'rw', isa => 'Int' );
has b => ( is => 'rw', isa => 'Str' );
has c => ( is => 'rw', isa => 'HashRef' );

around [ qw(a b c) ] => sub {
    my $orig = shift;
    my $self = shift;
    return $self->$orig() unless @_;
    my $aname = ???? # meta something?
    $self->myfunction($aname, @_);
};

How do I set $aname to be the name of the attribute that is being set. In other words, if

$foo->a(2)

I want to be able set $aname to a.

I could set an around for each attribute but that seems to be repetitive.

Miller

One method would be to use a for loop as modeled in Moose::Manual::MethodModifiers #Wrapping multiple methods at once:

for my $aname (qw(a b c)) {
    around $aname => sub {
        my $orig = shift;
        my $self = shift;
        return $self->$orig() unless @_;
        $self->myfunction( $aname, @_ );
    };
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I make it obvious which Firefox Profile is being used?

분류에서Dev

How to tell which image file is being used as Wallpaper in Wallch

분류에서Dev

How can I tell which user limit I am running into?

분류에서Dev

How do you tell which way up the iPhone is?

분류에서Dev

How to tell which facebook version API i'm using in php

분류에서Dev

How do I know which method/class is called when I test java GUI in eclipse?

분류에서Dev

vifm: how do I set the viewcolumn option in my vifmrc so that it applies to both panes?

분류에서Dev

How do I tell if a Windows 8.1 Product Keys is an OEM key?

분류에서Dev

How do I tell sudo to write files with a umask of 0022?

분류에서Dev

How can I tell the version of a package which will be installed before I install it?

분류에서Dev

How do I remove the ugly border around CALayer with cornerradius?

분류에서Dev

How do I pass an objects attribute as a parameter?

분류에서Dev

How do I check which key is pressed?

분류에서Dev

In C++, how can I tell WHICH piece of code is allocating what TYPE of objects?

분류에서Dev

How do I call a jQuery function on several jQuery objects?

분류에서Dev

How do I squelch specific messages from being logged in syslog?

분류에서Dev

How do I find the amount of items being selected in a ListBox?

분류에서Dev

In R, how can I see the signatures for which a generic method is implemented?

분류에서Dev

How do I tell Firefox to only keep persistent cookies from sites I want?

분류에서Dev

How do I tell what's happening when I postback my view?

분류에서Dev

How do I implement the onCreateOptionsMenu method in a SherlockFragment?

분류에서Dev

Java: How do I write a generic method?

분류에서Dev

How do I test a postconstruct method

분류에서Dev

How do I add the modified date of my folder files to my GridView?

분류에서Dev

How to tell when gradle is being run from AndroidStudio?

분류에서Dev

Clojure: how to tell if out is going to console or is being piped?

분류에서Dev

How do I Alter an attribute to change its datatype in Object type?

분류에서Dev

How do I tell apt-get install to stop trying to setup openssh-server?

분류에서Dev

How do I tell CMake to specify multiple linker script files to GCC?

Related 관련 기사

  1. 1

    How do I make it obvious which Firefox Profile is being used?

  2. 2

    How to tell which image file is being used as Wallpaper in Wallch

  3. 3

    How can I tell which user limit I am running into?

  4. 4

    How do you tell which way up the iPhone is?

  5. 5

    How to tell which facebook version API i'm using in php

  6. 6

    How do I know which method/class is called when I test java GUI in eclipse?

  7. 7

    vifm: how do I set the viewcolumn option in my vifmrc so that it applies to both panes?

  8. 8

    How do I tell if a Windows 8.1 Product Keys is an OEM key?

  9. 9

    How do I tell sudo to write files with a umask of 0022?

  10. 10

    How can I tell the version of a package which will be installed before I install it?

  11. 11

    How do I remove the ugly border around CALayer with cornerradius?

  12. 12

    How do I pass an objects attribute as a parameter?

  13. 13

    How do I check which key is pressed?

  14. 14

    In C++, how can I tell WHICH piece of code is allocating what TYPE of objects?

  15. 15

    How do I call a jQuery function on several jQuery objects?

  16. 16

    How do I squelch specific messages from being logged in syslog?

  17. 17

    How do I find the amount of items being selected in a ListBox?

  18. 18

    In R, how can I see the signatures for which a generic method is implemented?

  19. 19

    How do I tell Firefox to only keep persistent cookies from sites I want?

  20. 20

    How do I tell what's happening when I postback my view?

  21. 21

    How do I implement the onCreateOptionsMenu method in a SherlockFragment?

  22. 22

    Java: How do I write a generic method?

  23. 23

    How do I test a postconstruct method

  24. 24

    How do I add the modified date of my folder files to my GridView?

  25. 25

    How to tell when gradle is being run from AndroidStudio?

  26. 26

    Clojure: how to tell if out is going to console or is being piped?

  27. 27

    How do I Alter an attribute to change its datatype in Object type?

  28. 28

    How do I tell apt-get install to stop trying to setup openssh-server?

  29. 29

    How do I tell CMake to specify multiple linker script files to GCC?

뜨겁다태그

보관