| 1 | package CXC::constant::setonce; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Initialize a constant subroutine once. | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | our $VERSION = '0.01'; | |||||||||
| 11 | 2 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||
| 12 | 2 | my ( undef, @names ) = @_; | |||||||||
| 13 | 2 | my $target = caller; | |||||||||
| 14 | |||||||||||
| 15 | ## no critic ( TestingAndDebugging::ProhibitNoStrict) | ||||||||||
| 16 | 2 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | for my $name ( @names ) { | |||||||||
| 18 | |||||||||||
| 19 | 2 | my $fqdn = join q{::}, $target, $name; | |||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | *{$fqdn} = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 22 | 6 | state $stored = do { | |||||||||
| 23 | 2 | ▶ | die( "$fqdn: used before initialization" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | unless @_; | ||||||||||
| 25 | 1 | shift; | |||||||||
| 26 | }; | ||||||||||
| 27 | 5 | ▶ | @_ && die( "$fqdn: too many arguments" ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 3 | return $stored; | |||||||||
| 29 | 2 | }; | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 2 | 1; | |||||||||
| 35 | |||||||||||
| 36 | # | ||||||||||
| 37 | # This file is part of CXC-constant-setonce | ||||||||||
| 38 | # | ||||||||||
| 39 | # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory. | ||||||||||
| 40 | # | ||||||||||
| 41 | # This is free software, licensed under: | ||||||||||
| 42 | # | ||||||||||
| 43 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 44 | # | ||||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||