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 51     51   904 use 5.010;
  51         210  
4 51     51   321 use utf8;
  51         124  
  51         412  
5 51     51   2095 use namespace::autoclean;
  51         104  
  51         415  
6 51     51   4237 use Moo;
  51         153  
  51         327  
7 51     51   22800 use App::Sqitch::Types qw(Str);
  51         124  
  51         1000  
8             extends 'App::Sqitch::Plan::Line';
9              
10             our $VERSION = 'v1.6.1'; # 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 237367 my $class = shift;
25 743 50 33     11394 my $p = @_ == 1 && ref $_[0] ? { %{ +shift } } : { @_ };
  0         0  
26 743 100       4722 $p->{value} =~ s/\s+$// if $p->{value};
27 743   50     4895 $p->{op} //= '';
28 743         14820 return $p;
29             }
30              
31             sub format_name {
32 107     107 1 1647 my $self = shift;
33 107         855 return '%' . $self->hspace . $self->name;
34             }
35              
36             sub format_value {
37 107   100 107 1 907 shift->value // '';
38             }
39              
40             sub format_content {
41 106     106 1 208 my $self = shift;
42 106         360 join '', $self->format_name, $self->format_operator, $self->format_value;
43             }
44              
45             sub as_string {
46 106     106 1 4287 my $self = shift;
47 106         523 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-2026 David E. Wheeler, 2012-2021 iovation Inc.
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