| 1 | 4 | ▶ | use 5.008; # 8 = utf8, 6 = pragmas, our, 4 = __PACAKGE__ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package Package::Strictures::Register; | ||||||||||||||||||||||||||||
| 8 | 4 | $Package::Strictures::Register::VERSION = '1.000000'; | |||||||||||||||||||||||||||
| 9 | # ABSTRACT: Create compile-time constants that can be tweaked by users with Package::Strictures. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Package::Strictures::Registry (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub import { | ||||||||||||||||||||||||||||
| 17 | 3 | ▶ | my ( $self, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | if ( not %params ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | Carp::carp( __PACKAGE__ . ' called with no parameters, skipping magic' ); | |||||||||||||||||||||||||||
| 21 | 0 | return; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | my (@caller) = caller; | |||||||||||||||||||||||||||
| 25 | 3 | my $package = $caller[0]; | |||||||||||||||||||||||||||
| 26 | 3 | ▶ | $package = $params{-for} if exists $params{-for}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | if ( not exists $params{-setup} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | Carp::croak("Can't setup strictures for package '$package', need -setup "); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | $self->_setup( $params{-setup}, $package ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | return; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub _setup { | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | my ( $self, $params, $package ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_setup: called CC=7 SCAR=22.3
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | my $reftype = ref $params; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | if ( not 'HASH' eq $reftype ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | Carp::croak(qq/ -setup => can presently only support a HASH. Got '$reftype'/); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | if ( ( not exists $params->{-strictures} ) && ( not exists $params->{-groups} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"-strictures"} or exists $params->{"-groups"}
MC/DC0%0/2
exists $params->{"-strictures"} or exists $params->{"-groups"}
exists $params->{"-strictures"}
exists $params->{"-groups"}
Truth table33%1/3
A or B
A= exists $params->{"-strictures"}B= exists $params->{"-groups"}
| |||||||||||||||||||||||||||||
| 47 | 0 | Carp::croak('Neither -setup => { -strictures } or -setup => { -groups } provided.'); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | if ( exists $params->{-groups} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 3 | Carp::carp('-groups support is not yet implemented'); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | $params->{-strictures} = {} unless exists $params->{-strictures}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | $params->{-groups} = {} unless exists $params->{-groups}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 3 | $self->_setup_strictures( $params->{-strictures}, $package ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub _setup_strictures { | ||||||||||||||||||||||||||||
| 63 | 3 | ▶ | my ( $self, $strictures, $package ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_setup_strictures: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 64 | 3 | my $reftype = ref $strictures; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | if ( not 'HASH' eq $reftype ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | Carp::croak( qq/Can't handle anything except a HASH ( Got $reftype )/ | |||||||||||||||||||||||||||
| 68 | . qq/ for param -setup => { -strictures => } in -setup for $package/ ); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | for my $subname ( keys %{$strictures} ) { | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | $self->_setup_stricture( $strictures->{$subname}, $package, $subname ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 3 | return; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub _setup_stricture { | ||||||||||||||||||||||||||||
| 80 | ## no critic 'ProhibitNoStrict' | ||||||||||||||||||||||||||||
| 81 | 3 | ▶ | my ( $self, $prototype, $package, $name ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_setup_stricture: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if ( not exists $prototype->{default} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | Carp::croak("Prototype for `$package`::`$name` lacks a [required] ->{'default'} "); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 3 | $self->_advertise_stricture( $package, $name ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 3 | require Import::Into; | |||||||||||||||||||||||||||
| 89 | 3 | require constant; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | constant->import::into( $package, $name, $self->_fetch_stricture_value( $package, $name, $prototype->{default} ) ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | return; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub _advertise_stricture { | ||||||||||||||||||||||||||||
| 97 | 3 | ▶ | my ( undef, $package, $name ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_advertise_stricture: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | 3 | Package::Strictures::Registry->advertise_value( $package, $name ); | |||||||||||||||||||||||||||
| 99 | 3 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub _fetch_stricture_value { | ||||||||||||||||||||||||||||
| 103 | 3 | ▶ | my ( undef, $package, $name, $default ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_fetch_stricture_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | if ( Package::Strictures::Registry->has_value( $package, $name ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 2 | return Package::Strictures::Registry->get_value( $package, $name ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 1 | return $default; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||