| 1 | # | ||||||||||||
| 2 | # This file is part of Tie-IxHash-FixedSize | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # This software is copyright (c) 2018 by Michael Schout. | ||||||||||||
| 5 | # | ||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 8 | # | ||||||||||||
| 9 | |||||||||||||
| 10 | package Tie::IxHash::FixedSize; | ||||||||||||
| 11 | 1 | $Tie::IxHash::FixedSize::VERSION = '1.02'; | |||||||||||
| 12 | # ABSTRACT: Tie::IxHash with a fixed maximum size | ||||||||||||
| 13 | |||||||||||||
| 14 | 1 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 1 | ▶ | use parent 'Tie::IxHash'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | # location of size field in @$self. Tie::IxHash uses 0-3 | ||||||||||||
| 20 | 1 | ▶ | use constant SIZE_IX => 4; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | |||||||||||||
| 22 | 1 | ▶ | sub TIEHASH { | ||||||||||
|
Subroutine
TIEHASH: called CC=4 SCAR=14.3
| |||||||||||||
| 23 | 1 | my $class = shift; | |||||||||||
| 24 | 1 | ▶ | my $conf = shift if ref $_[0] eq 'HASH'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | |||||||||||||
| 26 | 1 | ▶ | $conf ||= {}; | ||||||||||
|
Condition50%1/2
$conf ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||
| 27 | |||||||||||||
| 28 | 1 | my $self = $class->SUPER::TIEHASH(@_); | |||||||||||
| 29 | |||||||||||||
| 30 | 1 | ▶ | if ($conf->{size}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 1 | $self->[SIZE_IX] = $conf->{size}; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 1 | return $self; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | 7 | ▶ | sub STORE { | ||||||||||
|
Subroutine
STORE: called CC=3 SCAR=11.0
| |||||||||||||
| 38 | 7 | my $self = shift; | |||||||||||
| 39 | |||||||||||||
| 40 | 7 | $self->SUPER::STORE(@_); | |||||||||||
| 41 | |||||||||||||
| 42 | 7 | ▶ | if (my $max_size = $self->[SIZE_IX]) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 4 | ▶ | while ($self->Keys > $max_size) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 4 | $self->Shift; | |||||||||||
| 45 | } | ||||||||||||
| 46 | } | ||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 1 | 1; | |||||||||||
| 50 | |||||||||||||
| 51 | __END__ | ||||||||||||