previous has asked for the wisdom of the Perl Monks concerning the following question:
My problem is that when I call the reference from inside the txt_box object as shown below the supplied argument "$self->{contents}" isn't showing up at all. By contrast if I supply a reference to non-oop sub like this...$self->{txt_box}=txt_box->new( $self->{frm}, sub {$self->updt} );
then "$self->{contents}" is passed fine. Here's how I'm calling the references$self->{txt_box}=txt_box->new( $self->{frm}, \&test_if_txt_box_content +s_passed_back );
I'm just wondering why the method isn't "seeing" that argument. Any help much appreciated.sub new { my $class = shift; my $self = {}; bless( $self, $class ); +#std line $self->{parent_widg}=shift; $self->{sub_to_call_on_keypress}=shift; <===================LOOK + HERE $self->{contents}=''; $self->{entry}=$self->{parent_widg}->new_ttk__entry( -width => 50, + -textvariable => \$self->{contents}, ); $self->{entry}->g_pack( -expand => 0, -fill => 'x', -side => top) +; #-fill => 'both' globals::new_bindtag('new_tag',$self->{entry},4); Tkx::bind( 'new_tag', "<Key>", [ sub { $self->upon_keypress(@_) }, + Tkx::Ev("%W","%K","%k") ] ); return $self; } #std line sub upon_keypress { #calls the sub/method you supplied...if an ordinar +y sub you supply \&sub_nm if method then just obj->method_nm my ($self, $win, $key_nm, $key_no) = @_; #tick print "in upon_keypress and so far you've got $self->{contents}\n +"; #tick $self->{sub_to_call_on_keypress}->( $self->{contents} ); #bug her +e...$self->{contents} gets passed to ORDINARY SUB but not updt method + <===================LOOK HERE }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unable to call a method reference with an argument
by NetWallah (Canon) on Dec 07, 2015 at 21:59 UTC | |
by Anonymous Monk on Dec 07, 2015 at 23:08 UTC | |
|
Re: unable to call a method reference with an argument
by kennethk (Abbot) on Dec 07, 2015 at 21:48 UTC | |
by Anonymous Monk on Dec 07, 2015 at 23:20 UTC | |
by Anonymous Monk on Dec 07, 2015 at 23:40 UTC |