KiokuDB

 view release on metacpan or  search on metacpan

lib/KiokuDB/Collapser/Buffer.pm  view on Meta::CPAN

    my ( $self, $data, $flatten ) = @_;

    if ( ref $data eq 'KiokuDB::Reference' ) {
        my $id = $data->id;

        if ( my $entry = $flatten->{$id} ) {
            # replace reference with data from entry, so that the
            # simple data is inlined, and mark that entry for removal
            $self->compact_entry($entry, $flatten);

            if ( $entry->tied or $entry->class ) {
                $entry->clear_id;
                $_[1] = $entry;
            } else {
                $_[1] = $entry->data;
            }
            return 1;
        }
    } elsif ( ref($data) eq 'ARRAY' ) {
        ref && $self->compact_data($_, $flatten) for @$data;
    } elsif ( ref($data) eq 'HASH' ) {
        ref && $self->compact_data($_, $flatten) for values %$data;
    } elsif ( ref($data) eq 'SCALAR' || ref($data) eq 'REF' ) {
        $self->compact_data($$data, $flatten);
    } elsif ( ref($data) eq 'KiokuDB::Entry' ) {
        $self->compact_entry($data, $flatten);
    } else {
        # passthrough
    }

    return;
}

sub imply_root {
    my ( $self, @ids ) = @_;

    my $entries = $self->_entries;

    foreach my $id ( @ids ) {
        my $entry = $entries->{$id} or next;
        next if $entry->has_root; # set by typemap
        $entry->root(1);
    }
}

sub commit {
    my ( $self, $backend ) = @_;

    my $l = $self->live_objects;

    $self->insert_to_backend($backend);
    $self->update_entries( in_storage => 1 );
}

sub insert_to_backend {
    my ( $self, $backend ) = @_;

    $backend->insert($self->entries);
}

sub update_entries {
    my ( $self, @shared_args ) = @_;

    my ( $e, $o ) = ( $self->_entries, $self->_ids );

    my $l = $self->live_objects;

    my $args = $self->_entry_args;

    foreach my $id ( keys %$e ) {
        my ( $object, $entry ) = ( $o->{$id}, $e->{$id} );

        my @args = @{ $args->{$id} || [] }; # FIXME XXX FIXME FIXME XXX BLAH BLAH

        $l->register_entry( $id => $entry, @shared_args );

        unless ( $l->object_to_id($object) ) {
            $l->register_object( $id => $object, @args );
        } else {
            $l->update_object_entry( $object, $entry, @args );
        }
    }
}

__PACKAGE__->meta->make_immutable;

__PACKAGE__

__END__

=pod

=encoding UTF-8

=head1 NAME

KiokuDB::Collapser::Buffer

=head1 VERSION

version 0.57

=head1 AUTHOR

Yuval Kogman <nothingmuch@woobling.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 1.734 second using v1.01-cache-2.11-cpan-5b529ec07f3 )