in reply to code ref

It probably stands to reason you should re-think your design, because this looks highly unusual.

If you are determined to make it work, then this should fit the bill:
$mw->Button(command => sub { $self->func1($a) })->pack();
Instead of using a subroutine reference, this uses an anonymous subroutine which establishes the correct object and parameters. Note, however, that if $self changes, the subroutine is a closure and might not have the same value as you'd expect. Test carefully.

Replies are listed 'Best First'.
Re: Re: Declaring Code Reference With Parameters
by pg (Canon) on Nov 10, 2002 at 01:27 UTC
    I agree with you, have to rethink the design. The classes in Perl is somehow very awkward, and unusual. It is heavyly hacked, and does not really stands on all the good basics for OO programming.
      You should take a look at Damian Conway's book on OO programming in Perl - it's both a great introduction for newcomers to the language ( or OO ) and a valuable resource for advanced programmers. The book is dense with good design examples in OO Perl, some of them highly original. It might change your mind about Perl's OO features.

      I used to be a bit put off by the way Perl handles OO, but in time, you get used to it, and the inconvenience of various things is no longer an issue. You do, after all, have many conveniences to make up for these.

      In the end, you can get the job done just fine using Perl OO.