File Coverage

blib/lib/Unix/Conf/Bind8/Conf/Comment.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 12 0.0
condition 0 2 0.0
subroutine 3 6 50.0
pod 2 2 100.0
total 14 48 29.1


line stmt bran cond sub pod time code
1             # Comment.pm
2             #
3             # Copyright Karthik Krishnamurthy
4              
5             =head1 NAME
6              
7             Unix::Conf::Bind8::Conf::Comment - Class for handling comments
8             between directives.
9              
10             =head1 SYNOPSIS
11              
12             use Unix::Conf::Bind8;
13              
14             my ($conf, $acl);
15             $conf = Unix::Conf::Bind8->new_conf (
16             FILE => '/etc/named.conf',
17             SECURE_OPEN => 1,
18             ) or $conf->die ("couldn't open `named.conf'");
19              
20             $acl = $conf->new_acl (
21             NAME => 'extremix.net-slaves',
22             ELEMENTS => [ qw (10.0.0.2 10.0.0.3) ],
23             ) or $acl->die ("couldn't create acl `extremix.net-slaves'");
24              
25             $comment = $conf->new_comment (
26             COMMENT => '// Elements of this Acl are allowed to transfer this zone',
27             WHERE => 'BEFORE',
28             WARG => $acl,
29             ) or $comment->die ("couldn't create comment");
30              
31             This class is not meant to be used directly, but is used instead by the
32             parser to store intra directive comments.
33              
34             =head1 METHODS
35              
36             =cut
37              
38             package Unix::Conf::Bind8::Conf::Comment;
39              
40 10     10   47 use strict;
  10         19  
  10         355  
41 10     10   45 use warnings;
  10         15  
  10         264  
42 10     10   51 use base qw (Unix::Conf::Bind8::Conf::Directive);
  10         107  
  10         6577  
43              
44             =over 4
45              
46             =item new ()
47              
48             Arguments
49             COMMENT => 'comment',
50             WHERE => 'FIRST'|'LAST'|'BEFORE'|'AFTER'
51             WARG => Unix::Conf::Bind8::Conf::Directive subclass object
52             # WARG is to be provided only in case WHERE eq 'BEFORE
53             # or WHERE eq 'AFTER'
54             PARENT => reference, # to the Conf object datastructure.
55              
56             Class constructor
57             Creates a Unix::Conf::Bind8::Conf::Comment object and returns it,
58             on success, an Err object otherwise. Do not use this constructor directly.
59             Use the Unix::Conf::Bind8::Conf::new_comment method () instead.
60              
61             =cut
62              
63             sub new
64             {
65 0     0 1   my $self = shift ();
66 0           my $new = bless ({});
67 0           my %args = @_;
68 0           my $ret;
69              
70 0 0         return (Unix::Conf->_err ('new', "PARENT not defined"))
71             unless ($args{PARENT});
72 0 0         $ret = $new->_parent ($args{PARENT}) or return ($ret);
73 0 0 0       $ret = $new->comment ($args{COMMENT}) or return ($ret)
74             if ($args{COMMENT});
75 0 0         $args{WHERE} = 'LAST' unless ($args{WHERE});
76 0 0         $ret = Unix::Conf::Bind8::Conf::_insert_in_list ($new, $args{WHERE}, $args{WARG})
77             or return ($ret);
78 0           return ($new);
79             }
80              
81             =item comment ()
82              
83             Object method.
84             Get/set the comment. If argument is passed, sets the comment, and returns
85             true on success, an Err object otherwise. If no argument is passed, returns
86             the set value.
87              
88             =cut
89              
90             sub comment
91             {
92 0     0 1   my ($self, $comment) = @_;
93              
94 0 0         if ($comment) {
95 0           $self->_rstring (\$comment);
96 0           return (1)
97             }
98 0           return (${$self->_rstring ()});
  0            
99             }
100              
101             sub __render
102             {
103 0     0     return (1);
104             }
105              
106             1;