DHCPd/OMAPI/Sugar.pm

filter: Statementstmt 82.8% 29 / 35 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 30.7% 4 / 13 Podpod 100% 1 / 1 totaltotal 70.9% 44 / 62 CC 7 SCAR 12.7
CC
7
Cov
83%
omapi_attr
7.7
__ANON__
1.2
__ANON__
1.2
CRAP 3.5
« DHCPd/Config/Key.pm ↑ Summary DHCPd/Config/FailoverPeer.pm »
1 package Net::ISC::DHCPd::OMAPI::Sugar;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::OMAPI::Sugar - Moose sugar for omapi classes
6  
7 =head1 SYNOPSIS
8  
9 use Net::ISC::DHCPd::OMAPI::Sugar; # not use Moose
10  
11 omapi_attr foo => ( isa => State, ... );
12  
13 =cut
14  
15 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Net::ISC::DHCPd::Types ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 my @types = Net::ISC::DHCPd::Types->get_type_list;
20  
21 =head1 FUNCTIONS
22  
23 =head2 omapi_attr
24  
25 omapi_attr $name => %attr;
26  
27 C<%attr> is by default:
28  
29 (
30 is => "rw",
31 predicate => "has_$name",
32 traits => [qw/Net::ISC::DHCPd::OMAPI::Meta::Attribute/],
33 )
34  
35 It will also set "coerce => 1", when "isa" is one of L<Moose>
36 types from L<Net::ISC::DHCPd::Types>.
37  
38 =cut
39  
40 185 ▶sub omapi_attr {
Subroutine omapi_attr: called CC=7 SCAR=20.4
Pod documented
41 185 my $class = shift;
42 185 ▶ my $names = ref $_[0] eq 'ARRAY' ? shift : [shift];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 6 179 185
43 185 my %opts = @_;
44 185 my $to_raw;
45  
46 185 ▶ if(my $type = $opts{'isa'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $opts{'isa'}) { } 185 0 185
47 185 ▶ if($type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion) 94 91 185
Condition66%2/3
$type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion
!ll&&!rl&&r
91094
MC/DC50%1/2
$type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion
$type =~ /^Net::ISC::DHCPd::Types/ $type->coercion
Truth table66%2/3
A and B
A= $type =~ /^Net::ISC::DHCPd::Types/B= $type->coercion
ABresult
0X0
100
111
48 94 $type =~ s/Net::ISC::DHCPd::Types:://;
49 94 $opts{'coerce'} = 1;
50 94 $to_raw = Net::ISC::DHCPd::Types->can("from_$type");
51 }
52 }
53 else {
54 0 confess '"isa" is required for omapi_attr()';
55 }
56  
57 185 for my $name (@$names) {
58 191 $class->meta->add_attribute($name => (
59 is => 'rw',
60 predicate => "has_$name",
61 clearer => "clear_$name",
62 traits => [qw/Net::ISC::DHCPd::OMAPI::Meta::Attribute/],
63 %opts,
64 ));
65 $class->meta->add_method("raw_$name" =>
66 0 ▶ $to_raw ? sub { shift->$to_raw($name) } : sub { shift->$name }
Subroutine __ANON__: not called CC=1 SCAR=1.6
Subroutine __ANON__: not called CC=1 SCAR=1.6
Subroutine raw_local_state: not called CC=1 SCAR=1.6
Subroutine raw_partner_port: not called CC=1 SCAR=1.6
Subroutine raw_starts: not called CC=1 SCAR=1.6
Subroutine raw_circuit_id: not called CC=1 SCAR=1.6
Subroutine raw_hardware_type: not called CC=1 SCAR=1.6
Subroutine raw_state: not called CC=1 SCAR=1.6
Subroutine raw_flags: not called CC=1 SCAR=1.6
67 191 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$to_raw ? : 11 180 191
68 }
69 }
70  
71 1 Moose::Exporter->setup_import_methods(
72 with_caller => [qw/omapi_attr/],
73 as_is => \@types,
74 );
75  
76 =head1 COPYRIGHT & LICENSE
77  
78 =head1 AUTHOR
79  
80 See L<Net::ISC::DHCPd>.
81  
82 =cut
83 1 __PACKAGE__->meta->make_immutable;
84 1 1;
« DHCPd/Config/Key.pm ↑ Summary DHCPd/Config/FailoverPeer.pm »