Aniki

 view release on metacpan or  search on metacpan

lib/Aniki/Row/Joined.pm  view on Meta::CPAN

package Aniki::Row::Joined;
use 5.014002;

use strict;
use warnings;

use Carp qw/croak/;

sub new {
    my ($class, @rows) = @_;
    my %rows = map { $_->table_name => $_ } @rows;
    return bless \%rows => $class;
}

sub can {
    my ($invocant, $method) = @_;
    my $code = $invocant->SUPER::can($method);
    return $code if defined $code;

    if (ref $invocant) {
        my $self       = $invocant;
        my $table_name = $method;
        return sub { shift->{$table_name} } if exists $self->{$table_name};
    }

    return undef; ## no critic
}

our $AUTOLOAD;
sub AUTOLOAD {
    my $invocant = shift;
    my $table_name = $AUTOLOAD =~ s/^.+://r;

    if (ref $invocant) {
        my $self = $invocant;
        return $self->{$table_name} if exists $self->{$table_name};
    }

    my $msg = sprintf q{Can't locate object method "%s" via package "%s"}, $table_name, ref $invocant || $invocant;
    croak $msg;
}

sub DESTROY {} # no autoload

1;
__END__

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.447 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )