disclaimer: Without looking into the Tk source m'self...

What the line $viewer->bind("<3>", [\&post_popup_menu]) does is call the method 'bind' in (whatever class "ref $viewer" tells you) with the parameter list: ($viewer, "<3>", $arrayref). That $arrayref is the new array reference created by the  [  ] operator, which in turn contains only the CODE ref (created by the  \& operator(s?) ) to post_popup_menu.

Note that a CODE ref cannot have arguments associated with it; the arguments are provided by the (eventual) caller. (If you wanted to pass certain args, you could use a closure to wrap the callback, e.g.  [ sub { &some_function ($whatever, @_); } ])

When your callback function (post_popup_menu) is called, it looks like it receives a parameter telling it 'who called,' which from what you said here, would be $viewer. (the 'shift' pulls the next - or in this case, first - argument to the subroutine off @_.) This object then appears to have stored the X and Y location of the event for which you were called - in this example, "<3>", a right-click (mouse button 3 click; could be on the left ;-) ).

I'd assume, then, that $viewer_menu is the menu, and to "Post" it means to "stick it" at the X,Y coords given.

Those Data::Dumper outputs should be interesting; you might want to poke around the XEvent structure to see what else you can do this way.


In reply to Re: How do Tk popup menus actually work? by baku
in thread How do Tk popup menus actually work? by Falkkin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.