| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package MooseX::Role::JSONObject::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use v5.012; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use version; our $VERSION = version->declare("v0.1.0"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use List::Util qw/pairfirst/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Method::Signatures; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | func identify_type(Any $val, Moose::Meta::Attribute $attr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.5
Subroutine
identify_type: called CC=16 SCAR=33.5
Branch: 5 branches
Condition33%2/6
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"Any"}
"Method::Signatures"->_make_constraint("Any")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"}
"Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Any"}B= "Method::Signatures"->_make_constraint("Any")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"}B= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 93 | ▶ | if (!$attr->has_type_constraint) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if (!defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | die "MooseX::Role::JSONObject::SKIP\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } elsif (ref $val eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return ('array', '*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } elsif (ref $val eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | return ('hash', '*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return ['*']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 93 | ▶ | if (!defined $val && !$attr->is_required) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $val or $attr->is_required
MC/DC100%2/2
defined $val or $attr->is_required
defined $val
$attr->is_required
Truth table100%3/3
A or B
A= defined $valB= $attr->is_required
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | die "MooseX::Role::JSONObject::SKIP\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 92 | my $type = $attr->type_constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 92 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 124 | again: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | my @handlers = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'Object' => ['obj', $type->name], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'Num' => ['num'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'Str' => ['str'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'Bool' => ['bool'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'Maybe' => ['maybe', '#PARAM'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'ArrayRef' => ['array', '#PARAM'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'HashRef' => ['hash', '#PARAM'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 124 | ▶ | my (undef, $list) = pairfirst { $type->is_a_type_of($a) } @handlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 124 | ▶ | if (!defined $list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | die "FIXME: handle the type constraint for ".$attr->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 124 | push @res, @{$list}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 124 | ▶ | if ($res[$#res] eq '#PARAM') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 32 | pop @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 32 | $type = $type->{type_parameter}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 32 | goto again; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Apparently we're done looping over parameterized type constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 92 | return @res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | func get_value(Any $val, Moose::Meta::Attribute $attr, CodeRef $objfunc) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.3
Subroutine
get_value: called CC=11 SCAR=26.1
Branch: 7 branches
Condition66%6/9
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
$Method::Signatures::mutc{"cache"}{"CodeRef"} ||= "Method::Signatures"->_make_constraint("CodeRef")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"Any"}
"Method::Signatures"->_make_constraint("Any")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"}
"Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"CodeRef"} ||= "Method::Signatures"->_make_constraint("CodeRef")
$Method::Signatures::mutc{"cache"}{"CodeRef"}
"Method::Signatures"->_make_constraint("CodeRef")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Any"}B= "Method::Signatures"->_make_constraint("Any")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Moose::Meta::Attribute"}B= "Method::Signatures"->_make_constraint("Moose::Meta::Attribute")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"CodeRef"}B= "Method::Signatures"->_make_constraint("CodeRef")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 93 | my @type = identify_type($val, $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 92 | return get_type_value($val, \@type, $objfunc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | func get_type_value(Any $val, ArrayRef[Str] $type, CodeRef $objfunc) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
get_type_value: called CC=11 SCAR=25.3
Branch: 7 branches
Condition44%4/9
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"ArrayRef[Str]"} ||= "Method::Signatures"->_make_constraint("ArrayRef[Str]")
$Method::Signatures::mutc{"cache"}{"CodeRef"} ||= "Method::Signatures"->_make_constraint("CodeRef")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Any"} ||= "Method::Signatures"->_make_constraint("Any")
$Method::Signatures::mutc{"cache"}{"Any"}
"Method::Signatures"->_make_constraint("Any")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"ArrayRef[Str]"} ||= "Method::Signatures"->_make_constraint("ArrayRef[Str]")
$Method::Signatures::mutc{"cache"}{"ArrayRef[Str]"}
"Method::Signatures"->_make_constraint("ArrayRef[Str]")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"CodeRef"} ||= "Method::Signatures"->_make_constraint("CodeRef")
$Method::Signatures::mutc{"cache"}{"CodeRef"}
"Method::Signatures"->_make_constraint("CodeRef")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Any"}B= "Method::Signatures"->_make_constraint("Any")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"ArrayRef[Str]"}B= "Method::Signatures"->_make_constraint("ArrayRef[Str]")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"CodeRef"}B= "Method::Signatures"->_make_constraint("CodeRef")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 113 | my %handlers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | %handlers = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 21 | ▶ | 'obj' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 21 | my ($t, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 21 | my $tname = shift @{$t}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 21 | ▶ | if (@{$t}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | die "Internal error: ". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | "identify_type() returned ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | "extra data after 'obj': @{$t}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 21 | return $objfunc->($v, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Class::MOP::Class->initialize($tname)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 54 | ▶ | 'num' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 54 | return $val + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | ▶ | 'str' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | return $val.""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | 'bool' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return !!$val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | ▶ | 'maybe' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 27 | my ($t, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 27 | ▶ | return undef unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 13 | my $f = shift @{$t}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 13 | return $handlers{$f}->($t, $v, $a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | ▶ | 'array' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 7 | my ($t, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 15 | get_type_value($_, [@{$t}], $objfunc) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | } @{$v} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | 'hash' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | my ($t, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | return { map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | ($_, get_type_value($v->{$_}, [@{$t}], $objfunc)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | } keys %{$v} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 113 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 113 | my $type_first = shift @{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 113 | return $handlers{$type_first}->($type, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | func meta_to_json(Object $obj, Moose::Meta::Class $meta) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
meta_to_json: called CC=13 SCAR=26.9
Branch: 5 branches
Condition66%4/6
$Method::Signatures::mutc{"cache"}{"Object"} ||= "Method::Signatures"->_make_constraint("Object")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Object"} ||= "Method::Signatures"->_make_constraint("Object")
$Method::Signatures::mutc{"cache"}{"Object"}
"Method::Signatures"->_make_constraint("Object")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"}
"Method::Signatures"->_make_constraint("Moose::Meta::Class")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Object"}B= "Method::Signatures"->_make_constraint("Object")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"}B= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 28 | my @attrs = $meta->get_all_attributes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 28 | my $res = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 78 | my $name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 78 | my $hname = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 78 | ▶ | if ($attr->has_applied_traits && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->has_applied_traits and grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
MC/DC50%1/2
$attr->has_applied_traits and grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
$attr->has_applied_traits
grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
Truth table66%2/3
A and B
A= $attr->has_applied_traitsB= grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | grep $_ eq 'MooseX::Role::JSONObject::Meta::Trait', @{$attr->applied_traits}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | $hname = $attr->json_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 78 | my $v = $obj->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 78 | my $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 78 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 78 | $res->{$hname} = get_value($v, $attr, \&meta_to_json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 77 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 78 | my $msg = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 78 | ▶ | if (!$ok && $msg ne "MooseX::Role::JSONObject::SKIP\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ok and $msg ne "MooseX::Role::JSONObject::SKIP\n"
MC/DC0%0/2
not $ok and $msg ne "MooseX::Role::JSONObject::SKIP\n"
not $ok
$msg ne "MooseX::Role::JSONObject::SKIP\n"
Truth table66%2/3
not(A) and B
A= not $okB= $msg ne "MooseX::Role::JSONObject::SKIP\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | die "$msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 28 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | func meta_from_json(HashRef $data, Moose::Meta::Class $meta) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
meta_from_json: called CC=13 SCAR=27.6
Branch: 5 branches
Condition50%3/6
$Method::Signatures::mutc{"cache"}{"HashRef"} ||= "Method::Signatures"->_make_constraint("HashRef")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"HashRef"} ||= "Method::Signatures"->_make_constraint("HashRef")
$Method::Signatures::mutc{"cache"}{"HashRef"}
"Method::Signatures"->_make_constraint("HashRef")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"} ||= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
$Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"}
"Method::Signatures"->_make_constraint("Moose::Meta::Class")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"HashRef"}B= "Method::Signatures"->_make_constraint("HashRef")
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Moose::Meta::Class"}B= "Method::Signatures"->_make_constraint("Moose::Meta::Class")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | my @attrs = $meta->get_all_attributes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | my %res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | for my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | my $name = $attr->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | my $hname = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 15 | ▶ | if ($attr->has_applied_traits && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr->has_applied_traits and grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
MC/DC50%1/2
$attr->has_applied_traits and grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
$attr->has_applied_traits
grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
Truth table66%2/3
A and B
A= $attr->has_applied_traitsB= grep(($_ eq "MooseX::Role::JSONObject::Meta::Trait"), @{$attr->applied_traits;})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | grep $_ eq 'MooseX::Role::JSONObject::Meta::Trait', @{$attr->applied_traits}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | $hname = $attr->json_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 15 | my $v = $data->{$hname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 15 | my $ok; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 15 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 15 | $res{$name} = get_value($v, $attr, \&meta_from_json); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 15 | $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 15 | my $msg = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 15 | ▶ | if (!$ok && $msg ne "MooseX::Role::JSONObject::SKIP\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $ok and $msg ne "MooseX::Role::JSONObject::SKIP\n"
MC/DC0%0/2
not $ok and $msg ne "MooseX::Role::JSONObject::SKIP\n"
not $ok
$msg ne "MooseX::Role::JSONObject::SKIP\n"
Truth table33%1/3
not(A) and B
A= not $okB= $msg ne "MooseX::Role::JSONObject::SKIP\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | die "$msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | return $meta->new_object(%res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||