| 1 | package List::AssignRef; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 1 | ▶ | use LV qw( lvalue ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 1 | ▶ | use Carp qw( confess ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 1 | ▶ | use constant { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 1 | SCALAR => 'SCALAR', | |||||||||||||||||
| 12 | ARRAY => 'ARRAY', | ||||||||||||||||||
| 13 | HASH => 'HASH', | ||||||||||||||||||
| 14 | 1 | }; | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 1 | ▶ | use constant { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | 1 | ERR_UNSUPPORTED => "Unsupported reference type: %s", | |||||||||||||||||
| 18 | ERR_MISMATCH => "Reference type mismatch: %s vs %s", | ||||||||||||||||||
| 19 | 1 | }; | |||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | 1 | ▶ | BEGIN { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 22 | 1 | $List::AssignRef::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||
| 23 | 1 | $List::AssignRef::VERSION = '0.005'; | |||||||||||||||||
| 24 | } | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 1 | ▶ | use Exporter::Shiny our @EXPORT = qw( deref ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | sub _confessf | ||||||||||||||||||
| 29 | 1 | ▶ | { | ||||||||||||||||
|
Subroutine
_confessf: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 30 | 1 | my $fmt = shift; | |||||||||||||||||
| 31 | 1 | confess sprintf $fmt, @_; | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | 6 | ▶ | sub deref (\[$@%]) :lvalue | ||||||||||||||||
|
Subroutine
deref: called CC=1 SCAR=0.6
Pod
documented
| |||||||||||||||||||
| 35 | { | ||||||||||||||||||
| 36 | 6 | my $given = shift; | |||||||||||||||||
| 37 | 0 | ▶ | lvalue get => sub { | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||
| 38 | 0 | ▶ | reftype($given) eq SCALAR ? $$given : | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 39 | reftype($given) eq ARRAY ? @$given : | ||||||||||||||||||
| 40 | reftype($given) eq HASH ? %$given : | ||||||||||||||||||
| 41 | _confessf(ERR_UNSUPPORTED, reftype($given)); | ||||||||||||||||||
| 42 | }, | ||||||||||||||||||
| 43 | 6 | ▶ | set => sub { | ||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||
| 44 | 6 | my $assign = shift; | |||||||||||||||||
| 45 | 6 | ▶ | reftype($given) eq reftype($assign) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 46 | or _confessf(ERR_MISMATCH, reftype($given), reftype($assign)); | ||||||||||||||||||
| 47 | 5 | ▶ | reftype($given) eq SCALAR ? ($$given = $$assign): | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 48 | reftype($given) eq ARRAY ? (@$given = @$assign): | ||||||||||||||||||
| 49 | reftype($given) eq HASH ? (%$given = %$assign): | ||||||||||||||||||
| 50 | _confessf(ERR_UNSUPPORTED, reftype($given)); | ||||||||||||||||||
| 51 | } | ||||||||||||||||||
| 52 | 6 | } | |||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | 1 | 1; | |||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||