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
|
6
|
|
|
6
|
|
29
|
use Moose; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
39
|
|
16
|
6
|
|
|
6
|
|
29626
|
use Net::ISC::DHCPd::Types ':all'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
75
|
|
17
|
6
|
|
|
6
|
|
28191
|
use Moose::Exporter; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
36
|
|
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
|
140
|
|
|
140
|
1
|
9152
|
my $class = shift; |
42
|
140
|
100
|
|
|
|
370
|
my $names = ref $_[0] eq 'ARRAY' ? shift : [shift]; |
43
|
140
|
|
|
|
|
335
|
my %opts = @_; |
44
|
140
|
|
|
|
|
131
|
my $to_raw; |
45
|
|
|
|
|
|
|
|
46
|
140
|
50
|
|
|
|
291
|
if(my $type = $opts{'isa'}) { |
47
|
140
|
100
|
66
|
|
|
454
|
if($type =~ /^Net::ISC::DHCPd::Types/ and $type->coercion) { |
48
|
72
|
|
|
|
|
41037
|
$type =~ s/Net::ISC::DHCPd::Types:://; |
49
|
72
|
|
|
|
|
4740
|
$opts{'coerce'} = 1; |
50
|
72
|
|
|
|
|
650
|
$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
|
140
|
|
|
|
|
256
|
for my $name (@$names) { |
58
|
143
|
|
|
|
|
572
|
$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; |