File Coverage

lib/Changes/NewLine.pm
Criterion Covered Total %
statement 35 35 100.0
branch 3 4 75.0
condition 5 7 71.4
subroutine 12 12 100.0
pod 5 5 100.0
total 60 63 95.2


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## Changes file management - ~/lib/Changes/NewLine.pm
3             ## Version v0.1.0
4             ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2022/12/08
7             ## Modified 2022/12/08
8             ## All rights reserved
9             ##
10             ##
11             ## This program is free software; you can redistribute it and/or modify it
12             ## under the same terms as Perl itself.
13             ##----------------------------------------------------------------------------
14             package Changes::NewLine;
15             BEGIN
16             {
17 11     11   10343 use strict;
  11         67  
  11         490  
18 11     11   72 use warnings;
  11         21  
  11         481  
19 11     11   67 use parent qw( Module::Generic );
  11         84  
  11         106  
20 11     11   912 use vars qw( $VERSION );
  11         18  
  11         732  
21 11     11   230 our $VERSION = 'v0.1.0';
22             };
23              
24 11     11   59 use strict;
  11         24  
  11         209  
25 11     11   63 use warnings;
  11         80  
  11         3138  
26              
27             sub init
28             {
29 26     26 1 2079 my $self = shift( @_ );
30 26         630 $self->{nl} = "\n";
31 26         69 $self->{raw} = undef;
32 26         66 $self->{_init_strict_use_sub} = 1;
33 26 50       129 $self->SUPER::init( @_ ) || return( $self->pass_error );
34 26         5144 return( $self );
35             }
36              
37             sub as_string
38             {
39 27     27 1 409 my $self = shift( @_ );
40 27         94 my $raw = $self->raw;
41 27   100     5238 $self->message( 4, "Raw new line was '", ( $raw // '' ), "'" );
42 27 100 66     891 if( defined( $raw ) && $raw->defined )
43             {
44 21         176 return( $raw );
45             }
46             else
47             {
48 6   50     25 my $nl = $self->nl // "\n";
49 6         1040 return( $self->new_scalar( "$nl" ) );
50             }
51             }
52              
53 23     23 1 3642 sub line { return( shift->_set_get_number( 'line', @_ ) ); }
54              
55 30     30 1 213503 sub nl { return( shift->_set_get_scalar_as_object( 'nl', @_ ) ); }
56              
57 50     50 1 5253 sub raw { return( shift->_set_get_scalar_as_object( 'raw', @_ ) ); }
58              
59             1;
60             # NOTE: POD
61             __END__
62              
63             =encoding utf-8
64              
65             =head1 NAME
66              
67             Changes::NewLine - New Line Class
68              
69             =head1 SYNOPSIS
70              
71             use Changes::NewLine;
72             my $nl = Changes::NewLine->new(
73             nl => "\n",
74             line => 12,
75             raw => "\t\n",
76             ) || die( Changes::NewLine->error, "\n" );
77             say $nl->as_string;
78              
79             =head1 VERSION
80              
81             v0.1.0
82              
83             =head1 DESCRIPTION
84              
85             This class represents a new line in the C<Changes> file.
86              
87             =head1 CONSTRUCTOR
88              
89             =head2 new
90              
91             This takes an hash or an hash reference of following options, and instantiate a new L<Changes::NewLine> object and returns it.
92              
93             If an error occurred, it returns an L<error|Module::Generic/error>
94              
95             =over 4
96              
97             =item * C<line>
98              
99             The line number where this new line was found in the C<Changes> file.
100              
101             =item * C<nl>
102              
103             The format of the new line to use with L</as_string>
104              
105             =item * C<raw>
106              
107             The raw initial value such as it is found when parsing the C<Changes> file with L<Changes/parse>
108              
109             =back
110              
111             =head1 METHODS
112              
113             =head2 as_string
114              
115             Returns a string representation of the new line. If C<raw> is defined with L</raw>, then that initial value will be used and returned, otherwise, it will use whatever value is set with L</nl>.
116              
117             Returns a L<scalar object|Module::Generic::Scalar>
118              
119             =head2 line
120              
121             Sets or gets the line number at which this new line appeared in the C<Changed> file. This is set by L<Changes/parse>
122              
123             Returns a L<number object|Module::Generic::Number>
124              
125             =head2 nl
126              
127             Sets or gets the new line sequence. For example C<\n>, or C<\r\n>, or C<\015\012> (same as previous, but more portable), etc.
128              
129             Returns a L<scalar object|Module::Generic::Scalar>
130              
131             =head2 raw
132              
133             Sets or gets the initial new line value. This is set upon parsing by L<Changes/parse>
134              
135             Returns a L<scalar object|Module::Generic::Scalar>
136              
137             =head1 AUTHOR
138              
139             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
140              
141             =head1 SEE ALSO
142              
143             L<Changes>, L<Changes::Release>, L<Changes::Group>, L<Changes::Changes>, L<Changes::Version>
144              
145             =head1 COPYRIGHT & LICENSE
146              
147             Copyright(c) 2022 DEGUEST Pte. Ltd.
148              
149             All rights reserved
150              
151             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
152              
153             =cut