However, When I check the source code(2) of Moose.pm, It seems to me that Moose.pm only use Moose::Object, that is , import its functions, instead of inheriting from it.

Actually Moose.pm is using Moose::Object, but it is not importing it's functions. In order for that to happen Moose::Object would have to define an import method as well as implement code to do the importing, neither of which you will see if you read the source.

Instead what happens is that Moose.pm defines an import method when it calls Moose::Exporter->setup_import_methods (about line 121 of Moose 0.94), that import method eventually calls the init_meta method defined right below that. In init_meta the "base_class" is assigned as 'Moose::Object' (assuming you didn't tell Moose to do otherwise) and eventually that will become the value of @ISA in your package. If you later call extends 'DBIx::Class' in your code, then the value of @ISA will then be DBIx::Class and no longer be Moose::Object.

The idea here is that Moose wants to provide you with the basic mechanisms needed by just about every object, such as: constructor (new), initialization mechanism (BUILDALL/BUILD), destructor (DESTROY), a teardown mechanism (DEMOLISHALL/DEMOLISH) and some introspection methods (does, DOES, meta, etc). In order to do this it makes the most sense to inherit from Moose::Object as a base class.

So, do I miss something here?

No, I think your just thinking about it too hard, and perhaps not asking the right questions. Based on your last few posts I suspect you are trying to mix Moose and DBIx::Class in some way. This has actually been done many times before to varying degrees of success, for some definition of success. The real solution is to re-write DBIx::Class in Moose and as far as I know there are some plans for doing just that (not sure how far along they are or aren't at this point).

If you want to understand the guts of Moose then I recommend first reading Class::MOP as it is simpler to digest and will give you the foundation with which to understand some of the more complex aspects of Moose. Perhaps you might also consider visiting us on IRC in #moose or #moose-dev, we will be happy to answer your detailed questions there. Myself (the original author) and the entire core development team are pretty much always in channel.

-stvn

In reply to Re: Moose & Moose::Object by stvn
in thread Moose & Moose::Object by sman

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.