in reply to Re^3: Improving your skills by reading module sources
in thread Improving your skills by reading module sources

Uhm, IO::Handle is just a bunch of methods that allows one to write $handle->func(args) instead of func $handle, args, with func being a core function. Many of its methods are of the form:
sub core_function { ... Check number of arguments ... core_function($_[0], $_[1], $_[2]); }
The objects are blessed handles, not the most convenient things if you want to subclass and actually store attributes, unless you want to go the inside-out-object way or some other "late great OO framework".

IO::Handle actually abstracts little (it just gives some different syntax), and isn't the easiest to subclass. It doesn't really impress me.

Replies are listed 'Best First'.
Re^5: Improving your skills by reading module sources
by BrowserUk (Patriarch) on Aug 03, 2011 at 18:44 UTC
    IO::Handle actually abstracts little (it just gives some different syntax),

    It is a base class, it doesn't need to do more. And if it doesn't need to, it shouldn't.

    If only more (usually self-described) OO-experts would learn that lesson.

    For reference, compare IO::Handle with IO::Moose::Handle.

    Contrast them for:

    • Simplicity
    • Understandability.
    • Maintainability.
    • Souce code weight.
    • Load time weight.
    • Run time efficiency.

    The former knocks the spots of the latter in every single category.

    and isn't the easiest to subclass.

    And yet, a whole hierarchy of modules -- IO::Seekable, IO::File, IO::Socket, IO::Socket::INET et al. -- are sub-classed on top of it.

    A file handle is a glob. It therefore has an associated hash and an associated array and even an associated scalar (which could hold a reference to a hash or an array). So, sub-classing is a doddle. It's just a matter of knowing the syntax.

    And if you don't like any of those mechanisms, then you could always use the Tie::Handle method as used by IO::Socket::DNS.

    It doesn't really impress me.

    Maybe simplicity and pragmatism isn't your thing?


    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.