ShipIt/State.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran n/a Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 77 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
set_version
2.0
version
2.0
CRAP 2.0
1 package ShipIt::State;
2 use strict;
3 use ShipIt::ProjectType::Perl;
4 use ShipIt::VC;
5  
6 =head1 NAME
7  
8 ShipIt::State - holds state between steps
9  
10 =head1 OVERVIEW
11  
12 An instance of type ShipIt::State is passed to each L<ShipIt::Step>'s
13 'run' method.
14  
15 =head1 INSTANCE METHODS
16  
17 =cut
18  
19 sub new {
20 my ($class, $conf) = @_;
21 my $self = bless {}, $class;
22 $self->{vc} = ShipIt::VC->new($conf);
23 $self->{changelogs} = [];
24 return $self;
25 }
26  
27 =head2 set_version
28  
29 $state->set_version("1.34");
30  
31 Set the version of this release. (is done by
32 L<ShipIt::Step::FindVersion>, early in the process, but perhaps you
33 want to write your own version-detecting/selecting step)
34  
35 =cut
36  
37 sub set_version {
38 my ($self, $ver) = @_;
39 $self->{version} = $ver;
40 }
41  
42 =head2 version
43  
44 $ver = $state->version
45  
46 Returns version of release, or dies if not yet set.
47  
48 =cut
49  
50 sub version {
51 my ($self, $ver) = @_;
52 return $self->{version} or die "No version yet set";
53 }
54  
55 =head2 pt
56  
57 $pt = $state->pt;
58  
59 Detects/instantiates this project's type (Perl vs autoconf, etc) and
60 returns a newly-created or previously-cached L<ShipIt::ProjectType>
61 instance.
62  
63 =cut
64  
65 sub pt {
66 my $self = shift;
67 return $self->{pt} ||= ShipIt::ProjectType->new;
68 }
69  
70 =head2 vc
71  
72 $vc = $state->vc;
73  
74 Detects/instantiates the version control system in use (svn, svk, etc)
75 and returns a newly-created or previously-cached L<ShipIt::VC>
76 instance.
77  
78 =cut
79  
80 # returns a version-control-type instance (created on first access)
81 sub vc {
82 my $self = shift;
83 return $self->{vc};
84 }
85  
86 =head2 add_changelog_file
87  
88 $state->add_changelog_file("CHANGES");
89  
90 Push a changelog file into the known list.
91  
92 =cut
93  
94 sub add_changelog_file {
95 my ($self, $file) = @_;
96 push @{$self->{changelogs}}, $file;
97 }
98  
99 =head2 changelog_files
100  
101 @files = $state->changelog_files;
102  
103 Returns list of known changelog files.
104  
105 =cut
106  
107 sub changelog_files {
108 my $self = shift;
109 return @{$self->{changelogs}};
110 }
111  
112 =head2 dry_run
113  
114 $dry = $state->dry_run;
115  
116 Accessor for "dry run" flag. If set, you shouldn't actually
117 commit/tag/upload stuff... just test if everything would've succeeded.
118  
119 =cut
120  
121 sub set_dry_run { $_[0]{dryrun} = $_[1] }
122 sub dry_run { $_[0]{dryrun} }
123  
124 =head2 skip_tests
125  
126 $dry = $state->skip_tests;
127  
128 Accessor for "skip tests" flag. If set, you should skip
129 tests. Presumably user already ran shipit, tests passed,
130 and then some later step failed, and they want to ship
131 quickly, without running entire test suite again.
132  
133 =cut
134  
135 sub set_skip_tests { $_[0]{skiptests} = $_[1] }
136 sub skip_tests { $_[0]{skiptests} }
137  
138 =head2 set_trial
139  
140 =head2 trial
141  
142 $state->set_trial(1);
143 $trial = $state->trial;
144  
145 Setter/getter for whether to make a TRIAL release for PAUSE. Unlike
146 using "_" in version strings to indicate developer releases, this way
147 you can keep the normal version numbers everywhere in your code, but
148 the final distribution file is renamed to C<-{version}-TRIAL.tar.gz>
149 before uploading, which indicates that this is a trial/beta release.
150  
151  
152 =cut
153  
154 sub set_trial { $_[0]{trial} = $_[1] }
155 sub trial { $_[0]{trial} }
156  
157 =head2 set_distfile
158  
159 =head2 distfile
160  
161 $state->set_distfile("foo.tar.gz");
162 $file = $state->distfile;
163  
164 Setter/getter for where the final distfile is. Useful so steps
165 that need to build the whole tree (say, in an early "make test"
166 phase), can keep it around, and later steps (like "make dist") can
167 access it, without recompiling everything again.
168  
169 =cut
170  
171 sub set_distfile { $_[0]{distfile} = $_[1] }
172 sub distfile { $_[0]{distfile} }
173  
174 1;