in reply to Re^3: A Few Questions About IO::File
in thread A Few Questions About IO::File

Similarly, there's no need to mention in the IO::File documentation that methods which return an object can be chained. That's just how method calls work in Perl (indeed, in most programming languages that support OO).

Thanks for the answer. Since I'm still relatively new to perl, I'd like a clarification first on what is the preferred way to do something in perl from the community (especially since OOP in perl is so raw and different from what I've encountered in other languages, I tried not to hold any assumption)

Replies are listed 'Best First'.
Re^5: A Few Questions About IO::File
by tobyink (Canon) on Mar 18, 2013 at 16:08 UTC

    "especially since OOP in perl is so raw and different from what I've encountered in other languages"

    That's an interesting thing to say. It's certainly a lot rawer (is that a word?) than Java or PHP, or many other languages. But Python and Perl's OO systems are actually fairly close to each other:

    • Methods are just functions which take an object as the first parameter.
    • Lack of true private methods; just use the convention of an underscore prefix. (Though Python also has name mangling for double underscores.)
    • Multiple inheritance and a default of depth-first mro.
    • Instances have slots where the class can store arbitrary data, and which do not need to be declared beforehand. (Or at least, this is true in Perl if the instances are blessed hashrefs, as is very common.)

    Moose provides a much more organised way of building classes in Perl if you're fed up of doing it "raw". IMHO, it's more powerful than the OO of pretty much any other mainstream programming language. Though it's just a layer over Perl's built-in crazy way of doing OO, so you can always dip into that as needed.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

      I think I read somewhere that Larry wall borrowed the object system directly from python. It's evident by the way both languanges need to unpack the invocant $self manually.

      While they are similar in concept, in perl I have to do a lot of manual works and boilerplates just to create a class with a bunch of accessors and mutators methods.

      And I am familiar with Moose, since my original reason to learn perl was to use the Catalyst framework which uses Moose (roles and Moose's type checking ability is da bomb). But I somehow got sidetracked and currently learning the guts of perl's object system. It's all good, fortunately since this is only a side project and I'm not hard pressed on time.

Re^5: A Few Questions About IO::File
by Anonymous Monk on Mar 18, 2013 at 15:29 UTC

    I wouldn't worry about it too much, read Modern Perl, you'll have the general idea

      Thanks for the pointer.