DBIx-Class-Async

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Async/Storage.pm  view on Meta::CPAN

package DBIx::Class::Async::Storage;

$DBIx::Class::Async::Storage::VERSION   = '0.65';
$DBIx::Class::Async::Storage::AUTHORITY = 'cpan:MANWAR';

use strict;
use warnings;
use Scalar::Util qw(weaken);

=head1 NAME

DBIx::Class::Async::Storage - Storage Layer for DBIx::Class::Async

=head1 VERSION

Version 0.65

=cut

lib/DBIx/Class/Async/Storage.pm  view on Meta::CPAN

=head2 new

    my $storage = DBIx::Class::Async::Storage->new(
        schema   => $schema,
        async_db => $bridge_engine,
    );

B<async_db> is the internal engine (the 'bridge') that handles
communication with the worker processes.

This constructor automatically weakens the reference to the parent L<schema>
to prevent circular reference leaks, ensuring that worker processes are
correctly reaped when the schema object goes out of scope.

=cut

sub new {
    my ($class, %args) = @_;

    # Standard DBIC storage expects a reference to the schema
    my $self = bless {
        _schema   => $args{schema},
        _async_db => $args{async_db}, # The worker pool engine
    }, $class;

    # WEAKEN the schema reference to prevent circular memory leaks
    # that caused your "5 vs 2 processes" test failure.
    weaken($self->{_schema}) if $self->{_schema};

    return $self;
}

=head1 METHODS

=head2 cursor

  my $cursor = $storage->cursor($resultset);

lib/DBIx/Class/Async/Storage.pm  view on Meta::CPAN


  my $schema = $storage->schema;

Returns the L<DBIx::Class::Async::Schema> object that this storage layer
is associated with.

This provides a back-reference from the storage to its parent schema,
allowing storage components to access schema-level information and other
ResultSources when needed.

Note: The schema reference is weakened internally to prevent circular
reference memory leaks between the schema and storage objects.

  my $storage = $schema->storage;
  my $parent_schema = $storage->schema;

  # Access schema configuration
  my $source = $parent_schema->source('User');

=cut



( run in 1.942 second using v1.01-cache-2.11-cpan-39bf76dae61 )