« blib/lib/IPC/PrettyPipe/Render/Template/Tiny.pm
↑ Summary
blib/lib/IPC/PrettyPipe/Render/Struct.pm »
| 1 | package IPC::PrettyPipe::Format; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # ABSTRACT: Format role | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | ## no critic (ProhibitAccessOfPrivateData) | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 26 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 26 | ▶ | use Module::Load; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 26 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 26 | our $VERSION = '0.13'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 26 | with 'MooX::Attributes::Shadow::Role'; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 26 | requires 'copy_into'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 26 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # IS THIS REALLY NEEDED????? this will convert an attribute with a | ||||||||||||||||||||
| 21 | # an undef value into a switch. | ||||||||||||||||||||
| 22 | # | ||||||||||||||||||||
| 23 | # undefined values are the same as not specifying a value at all | ||||||||||||||||||||
| 24 | 26 | if ( 0 ) { | |||||||||||||||||||
| 25 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | my ( $orig, $class ) = ( shift, shift ); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | my $attrs = $class->$orig( @_ ); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | delete @{$attrs}{ grep { !defined $attrs->{$_} } keys %$attrs }; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | return $attrs; | |||||||||||||||||||
| 34 | }; | ||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1779 | ▶ | sub _copy_attrs { | ||||||||||||||||||
|
Subroutine
_copy_attrs: called CC=3 SCAR=11.5
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 1779 | my ( $from, $to ) = ( shift, shift ); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 1779 | for my $attr ( @_ ) { | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 3558 | ▶ | next unless $from->${ \"has_$attr" }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 198 | ▶ | try { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||
| 47 | 198 | ▶ | if ( defined( my $value = $from->$attr ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 198 | $to->$attr( $value ); | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | $to->${ \"clear_$attr" }; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 0 | ▶ | catch { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | croak( | |||||||||||||||||||
| 62 | "unable to copy into or clear attribute $attr in object of type ", | ||||||||||||||||||||
| 63 | ref $to, | ||||||||||||||||||||
| 64 | ": $_\n" | ||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||
| 66 | 198 | }; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 1779 | return; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 548 | ▶ | sub copy_from { | ||||||||||||||||||
|
Subroutine
copy_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 548 | $_[1]->copy_into( $_[0] ); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 548 | return; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 1201 | ▶ | sub clone { | ||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 1201 | my $class = ref( $_[0] ); | |||||||||||||||||||
| 101 | 1201 | load $class; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 1201 | my $clone = $class->new; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 1201 | $_[0]->copy_into( $clone ); | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 1201 | return $clone; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 45 | ▶ | sub new_from_attrs { | ||||||||||||||||||
|
Subroutine
new_from_attrs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 45 | my $class = shift; | |||||||||||||||||||
| 122 | 45 | load $class; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 45 | return $class->new( $class->xtract_attrs( @_ ) ); | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 344 | ▶ | sub new_from_hash { | ||||||||||||||||||
|
Subroutine
new_from_hash: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 344 | my $contained = shift; | |||||||||||||||||||
| 142 | 344 | my $hash = pop; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 344 | ▶ | my $container = shift || caller(); | ||||||||||||||||||
|
Condition33%1/3
shift() || caller()
MC/DC0%0/2
shift() || caller()
shift()
caller()
Truth table33%1/3
A || B
A= shift()B= caller()
| |||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 344 | load $contained; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 344 | my $shadowed = $contained->shadowed_attrs( $container ); | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 344 | my %attr; | |||||||||||||||||||
| 151 | 344 | ▶ | while ( my ( $alias, $orig ) = each %{$shadowed} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 688 | ▶ | $attr{$orig} = $hash->{$alias} if exists $hash->{$alias}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 344 | return $contained->new( \%attr ); | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 26 | 1; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | # | ||||||||||||||||||||
| 163 | # This file is part of IPC-PrettyPipe | ||||||||||||||||||||
| 164 | # | ||||||||||||||||||||
| 165 | # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||
| 166 | # | ||||||||||||||||||||
| 167 | # This is free software, licensed under: | ||||||||||||||||||||
| 168 | # | ||||||||||||||||||||
| 169 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||
| 170 | # | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | __END__ | ||||||||||||||||||||