is this something like anonymous sub but gets applied before code is compiled?

It is a (specially) named block, called by Perl before processing the rest of the module. See perlmod for details.

But I don't understand how to access sub BEGIN

What do you mean by "access sub BEGIN"?

If you mean how do you call it? You don't.

If you mean how do you use the package? I think the answer is that in the normal way of things you wouldn't. It appears to be a sub package of a larger suite that is intended to be called internally only. The one subroutine (method?!) it contains--that rather nastily, remotely insinuates itself in to a complete different package space--is a rather clumsy replication of exists.

Basically, once the module is loaded, the hash has been constructed. But, the BEGIN block is probably unnecessary. The module would work just the same without it.

And whenever anyone calls SOAP::Deserializer::typecast() passing ($self, $value, $name, $attrs, $children, $type), if $type exists in the hash, it returns $value, otherwise undef.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re: sub BEGIN by BrowserUk
in thread sub BEGIN by Anonymous Monk

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.