Database-Join
view release on metacpan or search on metacpan
lib/Database/Join.pm view on Meta::CPAN
# Fast path: no join-key alias to exclude and no collision renames
@merged{keys %{$s}} = values %{$s};
} else {
for my $col (keys %{$s}) {
next if $skip_jc && $col eq $local_jc;
$merged{ $renames->{$col} // $col } = $s->{$col};
}
}
}
delete @merged{keys %{ $self->{_removed_cols} }}
if %{ $self->{_removed_cols} };
$self->{_schema_cache} = \%merged;
return $self->{_schema_cache};
}
=head2 updated
=head3 SYNOPSIS
my $ts = $join->updated();
=head3 DESCRIPTION
Returns the Unix timestamp of the most recent modification across all
component databases. This is the maximum of all individual C<updated()>
return values.
Use this to implement simple cache-invalidation logic: if C<updated()>
has advanced since your last snapshot, re-query.
=head3 API SPECIFICATION
=head4 Input
None.
=head4 Output
Unix timestamp (positive integer).
=head3 EXAMPLE
my $last_modified = $join->updated();
if ($last_modified > $my_cache_timestamp) {
$my_cache = $join->selectall_arrayref();
$my_cache_timestamp = $last_modified;
}
=head3 MESSAGES
C<updated()> does not emit any warnings or errors. Component databases that do
not implement C<updated()>, or whose C<updated()> throws, are silently skipped;
only defined return values contribute to the maximum. If no component database
implements C<updated()>, C<undef> is returned (same as C<List::Util::max> on an
empty list).
=cut
sub updated {
my ($self) = @_;
my @timestamps;
for my $db (@{ $self->{_dbs} }) {
my $ts;
do { local $@; $ts = eval { $db->updated() } };
push @timestamps, $ts if defined $ts;
}
return max(@timestamps);
}
=head2 set_logger
=head3 SYNOPSIS
$join->set_logger($log);
$join->set_logger(logger => $log); # named-pair form also accepted
=head3 DESCRIPTION
Attaches a new logger object to the join and propagates it to every component
database. The logger is used for diagnostic output by all component databases.
Non-blessed values (a log-level string such as C<"debug">, a filename, or a
code reference) are wrapped in C<Log::Abstraction->new(...)> automatically,
matching the behaviour of C<Database::Abstraction::set_logger>.
=head3 API SPECIFICATION
=head4 Input
logger Positional or named: a logger object, log-level string, filename,
or code reference (required). Non-blessed values are wrapped in
Log::Abstraction automatically.
=head4 Output
Returns C<$self> for method chaining.
=head3 EXAMPLE
# Log::Any is used here as an example; any object that implements
# debug() and info() (or whichever methods your component databases
# call internally) works equally well.
use Log::Any qw($log);
my $join = Database::Join->new(databases => [$db1, $db2], join_column => 'entry');
$join->set_logger($log);
# $log is now used by $join and by $db1 and $db2
# Named-pair form (mirrors Database::Abstraction API):
$join->set_logger(logger => $log);
=head3 MESSAGES
(croak) Usage: set_logger(logger => $logger)
-- Called with an undefined argument. Pass a valid logger object.
=cut
sub set_logger {
( run in 0.340 second using v1.01-cache-2.11-cpan-7da0f45c409 )