| 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
| |||||||||||||||||||||||||||||
| 43 | 185 | my %opts = @_; | |||||||||||||||||||||||||||
| 44 | 185 | my $to_raw; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 185 | ▶ | if(my $type = $opts{'isa'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 185 | ▶ | if($type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||