Cache-Profile

 view release on metacpan or  search on metacpan

lib/Cache/Profile/Compare.pm  view on Meta::CPAN

package Cache::Profile::Compare;
# ABSTRACT: Compare several caches

our $VERSION = '0.06';

use Moose;
use Carp qw(croak);
use Cache::Profile::CorrelateMissTiming;
use namespace::autoclean;

has profile_class => (
    isa => "ClassName",
    is  => "ro",
    default => "Cache::Profile::CorrelateMissTiming",
    required => 1,
);

has caches => (
    traits => [qw(Array)],
    isa => "ArrayRef[Object]",
    predicate => "has_caches",
    handles => {
        caches => "elements",
    },
);

has profiles => (
    traits => [qw(Array)],
    isa => "ArrayRef[Object]",
    lazy_build => 1,
    handles => {
        profiles => "elements",
    },
);

sub _build_profiles {
    my $self = shift;

    croak "'caches' or 'profiles' are required" unless $self->has_caches;

    [ map { $self->wrap_cache($_) } $self->caches ];
}

sub wrap_cache {
    my ( $self, $cache ) = @_;

    $self->profile_class->new( cache => $cache );
}

sub get { shift->_first_def( get => @_ ) }
sub compute { shift->_first_def( compute => @_ ) }

sub _first_def {
    my $self = shift;
    my $method = shift;

    my @all_rets;

    foreach my $cache ( $self->profiles ) {
        my @ret;
        if ( wantarray ) {
            @ret = $cache->$method(@_);
        } else {
            $ret[0] = $cache->$method(@_);
        }
        push @all_rets, \@ret;
    }

    if ( wantarray ) {



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