line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
2
|
|
|
2
|
|
9
|
use Moose; |
|
2
|
|
|
|
|
68
|
|
|
2
|
|
|
|
|
11
|
|
16
|
2
|
|
|
2
|
|
9950
|
use Net::ISC::DHCPd::Types ':all'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
36
|
|
17
|
2
|
|
|
2
|
|
8945
|
use Moose::Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub omapi_attr { |
41
|
64
|
|
|
64
|
1
|
3899
|
my $class = shift; |
42
|
64
|
100
|
|
|
|
183
|
my $names = ref $_[0] eq 'ARRAY' ? shift : [shift]; |
43
|
64
|
|
|
|
|
153
|
my %opts = @_; |
44
|
64
|
|
|
|
|
57
|
my $to_raw; |
45
|
|
|
|
|
|
|
|
46
|
64
|
50
|
|
|
|
144
|
if(my $type = $opts{'isa'}) { |
47
|
64
|
100
|
66
|
|
|
236
|
if($type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion) { |
48
|
32
|
|
|
|
|
18275
|
$type =~ s/Net::ISC::DHCPd::Types:://; |
49
|
32
|
|
|
|
|
2349
|
$opts{'coerce'} = 1; |
50
|
32
|
|
|
|
|
314
|
$to_raw = Net::ISC::DHCPd::Types->can("from_$type"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
confess '"isa" is required for omapi_attr()'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
64
|
|
|
|
|
134
|
for my $name (@$names) { |
58
|
67
|
|
|
|
|
341
|
$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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
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
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
84
|
|
|
|
|
|
|
1; |