DBICx::AutoDoc::Magic - Capture some otherwise unobtainable information about a DBIx::Class subclass


DBICx-AutoDoc documentation Contained in the DBICx-AutoDoc distribution.

Index


Code Index:

NAME

Top

DBICx::AutoDoc::Magic - Capture some otherwise unobtainable information about a DBIx::Class subclass

SYNOPSIS

Top

See dbicx-autodoc and DBICx::AutoDoc.

DESCRIPTION

Top

DBICx::AutoDoc::Magic is a DBIx::Class component used by DBICx::AutoDoc to capture some information that cannot be reverse-engineered out of a compiled DBIx::Class subclass.

METHODS

Top

This class has only two methods of it's own...

_autodoc

This is simply an accessor (a Class::Accessor::Grouped accessor, of type 'inherited' to be precise) that provides each of the subclasses with a suitable location to store the information this module collects for them.

_autodoc_record_relationship

This method is called by each of the overloaded methods, and merely records their arguments in the hashref stored in _autodoc, and then forwards the call on to the real method.

OVERLOADED METHODS

Top

This module overloads the following DBIx::Class methods. They are overloaded merely to call _autodoc_record_relationship and then they call the original method.

belongs_to

has_many

might_have

has_one

many_to_many

SEE ALSO

Top

DBICx::AutoDoc, dbicx-autodoc, DBIx::Class, DBIx::Class::Relationship

AUTHOR

Top

Jason Kohles, <email@jasonkohles.com>

COPYRIGHT AND LICENSE

Top


DBICx-AutoDoc documentation Contained in the DBICx-AutoDoc distribution.

package DBICx::AutoDoc::Magic;
use strict;
use warnings;
our $VERSION = '0.07';
use DBIx::Class::Relationship::Helpers;
use base qw( DBIx::Class );

__PACKAGE__->mk_group_accessors( inherited => qw( _autodoc ) );

my $func_body = <<'END';
    my $self = shift;
    $self->_autodoc_record_relationship( @_ );
    $self->maybe::next::method( @_ );
END

eval "sub $_ { $func_body }" for qw(
    has_many has_one might_have belongs_to many_to_many
);

# This needs to go after the stuff above, so Class::C3 can figure out the
# methods in this class
DBIx::Class::Relationship::Helpers->load_components( '+DBICx::AutoDoc::Magic' );

sub _autodoc_record_relationship {
    my $self = shift;

    my ( $method ) = ( caller( 1 ) )[3];
    $method =~ s/^.*:://;

    my $class = ref( $self ) || $self;
    if ( ! $class->_autodoc ) { $class->_autodoc( {} ) }

    push( @{ $class->_autodoc->{ 'relationships' } }, [ $method, @_ ] );
}

1;

__END__