in reply to Re^2: Question about __PACKAGE__
in thread Question about __PACKAGE__

When I trace into the source of DBIx::Class, why I did not see any mehtod like table(), add_columns(), or load_components()?

Replies are listed 'Best First'.
Re^4: Question about __PACKAGE__
by SpiceMan (Sexton) on Jan 22, 2010 at 04:58 UTC
    found them with grep, though:
    1:53 spiceman@cynic ~/perl5/lib/perl5 % grep -R 'sub add_columns ' DBIx
    DBIx/Class/CDBICompat/ColumnGroups.pm:sub add_columns {
    DBIx/Class/CDBICompat/ColumnCase.pm:sub add_columns {
    DBIx/Class/DynamicDefault.pm:sub add_columns {
    DBIx/Class/TimeStamp.pm:sub add_columns {
    DBIx/Class/ResultSource.pm:sub add_columns {
    DBIx/Class/ResultSourceProxy.pm:sub add_columns {
    
    1:53 spiceman@cynic ~/perl5/lib/perl5 % grep -R 'sub table ' DBIx
    DBIx/Class/ResultSetManager.pm:sub table {
    DBIx/Class/ResultSourceProxy/Table.pm:sub table {
    
    1:53 spiceman@cynic ~/perl5/lib/perl5 % grep -R 'sub load_components ' .
    ./Class/C3/Componentised.pm:sub load_components {
    
Re^4: Question about __PACKAGE__
by sman (Beadle) on Jan 22, 2010 at 05:36 UTC
    I found the corresponding classes that these three class methods belong to:

    DBIx::Class::ResultSourceProxy::Table
    table()
    add_columns()

    Class::C3::Componentised
    load_components()

    And I also know Class::C3::Componentised is the parent class of DBIx::Class that is the parent of Item, so this makes sense. But I don't know the relationship between DBIx::Class::ResultSourceProxy::Table and DBIx::Class.

    Any idea?

      Taking an educated guess with grep is indeed the easiest path sometimes.

      load_components loads modules and adds them as base class (kinda like use base does).

      load_components('Core') loads DBIx::Class::Core and makes DBIx::Class::Core a base class of your class.

      DBIx::Class::Core similarly uses load_components loads a number of modules (including DBIx::Class::ResultSourceProxy::Table) and adds them to its list of base classes.

      package Result::Item; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components( "InflateColumn::DateTime", "Core" ); print "Parents of Result::Item:\n"; print "$_\n" for @Result::Item::ISA; print "\n"; print "Parents of DBIx::Class::Core:\n"; print "$_\n" for @DBIx::Class::Core::ISA;
      Parents of Result::Item: DBIx::Class::InflateColumn::DateTime DBIx::Class::Core DBIx::Class Parents of DBIx::Class::Core: DBIx::Class::Relationship DBIx::Class::InflateColumn DBIx::Class::PK::Auto DBIx::Class::PK DBIx::Class::Row DBIx::Class::ResultSourceProxy::Table DBIx::Class
        I got your point. I guess I can change class Item to inherit from DBIx::Class::Core instead of DBIx::Class and comment out this line :
        __PACKAGE__->load_components( "InflateColumn::DateTime", "Core" );
        Am I right?
        Thanks for your reply.