File Coverage

blib/lib/App/Sqitch/Plan/Pragma.pm
Criterion Covered Total %
statement 26 27 96.3
branch 3 4 75.0
condition 4 7 57.1
subroutine 10 10 100.0
pod 4 5 80.0
total 47 53 88.6


line stmt bran cond sub pod time code
1             package App::Sqitch::Plan::Pragma;
2              
3 50     50   918 use 5.010;
  50         243  
4 50     50   338 use utf8;
  50         180  
  50         283  
5 50     50   1243 use namespace::autoclean;
  50         160  
  50         324  
6 50     50   4144 use Moo;
  50         171  
  50         368  
7 50     50   17743 use App::Sqitch::Types qw(Str);
  50         145  
  50         663  
8             extends 'App::Sqitch::Plan::Line';
9              
10             our $VERSION = 'v1.4.0'; # VERSION
11              
12             has value => (
13             is => 'ro',
14             isa => Str,
15             );
16              
17             has hspace => (
18             is => 'ro',
19             isa => Str,
20             default => '',
21             );
22              
23             sub BUILDARGS {
24 743     743 0 211264 my $class = shift;
25 743 50 33     9288 my $p = @_ == 1 && ref $_[0] ? { %{ +shift } } : { @_ };
  0         0  
26 743 100       3785 $p->{value} =~ s/\s+$// if $p->{value};
27 743   50     4166 $p->{op} //= '';
28 743         13318 return $p;
29             }
30              
31             sub format_name {
32 107     107 1 1194 my $self = shift;
33 107         681 return '%' . $self->hspace . $self->name;
34             }
35              
36             sub format_value {
37 107   100 107 1 941 shift->value // '';
38             }
39              
40             sub format_content {
41 106     106 1 176 my $self = shift;
42 106         303 join '', $self->format_name, $self->format_operator, $self->format_value;
43             }
44              
45             sub as_string {
46 106     106 1 1964 my $self = shift;
47 106         549 return $self->lspace
48             . $self->format_content
49             . $self->rspace
50             . $self->format_note;
51             }
52              
53             1;
54              
55             __END__
56              
57             =head1 Name
58              
59             App::Sqitch::Plan::Pragma.pm - Sqitch deployment plan blank line
60              
61             =head1 Synopsis
62              
63             my $plan = App::Sqitch::Plan->new( sqitch => $sqitch );
64             for my $line ($plan->lines) {
65             say $line->as_string;
66             }
67              
68             =head1 Description
69              
70             An App::Sqitch::Plan::Pragma represents a plan file pragma. See
71             L<App::Sqitch::Plan::Line> for its interface.
72              
73             =head1 Interface
74              
75             In addition to the interface inherited from L<App::Sqitch::Plan::Line>,
76             App::Sqitch::Plan::Line::Pragma adds a few methods of its own.
77              
78             =head2 Accessors
79              
80             =head3 C<value>
81              
82             The value of the pragma.
83              
84             =head3 C<op>
85              
86             The operator, including surrounding white space.
87              
88             =head3 C<hspace>
89              
90             The horizontal space between the pragma and its value.
91              
92             =head2 Instance Methods
93              
94             =head3 C<format_value>
95              
96             Formats the value for output. If there is no value, an empty string is
97             returned. Otherwise the value is returned as-is.
98              
99             =head1 Author
100              
101             David E. Wheeler <david@justatheory.com>
102              
103             =head1 License
104              
105             Copyright (c) 2012-2023 iovation Inc., David E. Wheeler
106              
107             Permission is hereby granted, free of charge, to any person obtaining a copy
108             of this software and associated documentation files (the "Software"), to deal
109             in the Software without restriction, including without limitation the rights
110             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111             copies of the Software, and to permit persons to whom the Software is
112             furnished to do so, subject to the following conditions:
113              
114             The above copyright notice and this permission notice shall be included in all
115             copies or substantial portions of the Software.
116              
117             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
121             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
122             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
123             SOFTWARE.
124              
125             =cut