| 1 | package Net::Gnats::PR; | ||||||||||||||||||||||||||||
| 2 | 40 | ▶ | use 5.010_000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strictures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 40 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 40 | $Net::Gnats::PR::VERSION = '0.22'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 40 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use Net::Gnats::Constants qw(FROM_FIELD REPLYTO_FIELD TO_FIELD CC_FIELD SUBJECT_FIELD SENDPR_VER_FIELD NOTIFY_FIELD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 40 | ▶ | use Net::Gnats::FieldInstance; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 40 | ▶ | use Net::Gnats::Attachment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 40 | $| = 1; | |||||||||||||||||||||||||||
| 19 | 40 | require Exporter; | |||||||||||||||||||||||||||
| 20 | 40 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 21 | 40 | our @EXPORT_OK = qw( serialize deserialize parse_line); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # TODO: These came from gnatsweb.pl for the parsepr and unparsepr routines. | ||||||||||||||||||||||||||||
| 24 | # should be done a better way? | ||||||||||||||||||||||||||||
| 25 | 40 | my $UNFORMATTED_FIELD = 'Unformatted'; | |||||||||||||||||||||||||||
| 26 | 40 | my $SYNOPSIS_FIELD = 'Synopsis'; | |||||||||||||||||||||||||||
| 27 | 40 | my $ORIGINATOR_FIELD = 'Originator'; | |||||||||||||||||||||||||||
| 28 | 40 | my $attachment_delimiter = "----gnatsweb-attachment----\n"; | |||||||||||||||||||||||||||
| 29 | 40 | my $SENDINCLUDE = 1; # whether the send command should include the field | |||||||||||||||||||||||||||
| 30 | 40 | our $REVISION = '$Id: PR.pm,v 1.8 2014/08/16 23:40:56 thacker Exp $'; #' | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | #****************************************************************************** | ||||||||||||||||||||||||||||
| 33 | # Sub: new | ||||||||||||||||||||||||||||
| 34 | # Description: Constructor | ||||||||||||||||||||||||||||
| 35 | # Args: hash (parameter list) | ||||||||||||||||||||||||||||
| 36 | # Returns: self | ||||||||||||||||||||||||||||
| 37 | #****************************************************************************** | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 new | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | The new() constructor does not expect any options. However, this may | ||||||||||||||||||||||||||||
| 44 | change in the future when PR initialization is moved from Net::Gnats | ||||||||||||||||||||||||||||
| 45 | to this class. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | my $pr = Net::Gnats::PR->new | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 19 | my ( $class, %options ) = @_; | |||||||||||||||||||||||||||
| 53 | 19 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 54 | 19 | $self->{number} = undef; | |||||||||||||||||||||||||||
| 55 | 19 | $self->{fieldlist} = []; | |||||||||||||||||||||||||||
| 56 | 19 | ▶ | return $self if not %options; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | return $self; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 asHash | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Returns the PR formatted as a hash. The returned hash contains field | ||||||||||||||||||||||||||||
| 66 | names as keys, and the corresponding field values as hash values. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | CHANGE ALERT: This method now returns all FieldInstance objects. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | DEPRECATION NOTICE: This accessor will be removed in the near future. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub asHash { | ||||||||||||||||||||||||||
|
Subroutine
asHash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | my ( $self ) = shift; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | return %{$self->{fields}} if defined($self->{fields}); #XXX Deep copy? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | return undef; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head2 asString | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Returns the PR object formatted as a Gnats recongizable string. The | ||||||||||||||||||||||||||||
| 83 | result is suitable for submitting to Gnats. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | my $serialized_pr = $pr->asString; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | DEPRECATION NOTICE: This accessor will be removed in the near future. | ||||||||||||||||||||||||||||
| 88 | Instead, use: | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | my $serialized_pr = $pr->serialize; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 7 | ▶ | sub asString { | ||||||||||||||||||||||||||
|
Subroutine
asString: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 7 | return Net::Gnats::PR->serialize($self, | |||||||||||||||||||||||||||
| 97 | Net::Gnats->current_session->username); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head2 getField | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Returns the string value of a PR field. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | $pr->getField('field'); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | DEPRECATION NOTICE: this will be deprecated in the near future. Use instead: | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | $r->get_field('field')->value | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | ▶ | sub getField { | ||||||||||||||||||||||||||
|
Subroutine
getField: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 2 | my ( $self, $field ) = @_; | |||||||||||||||||||||||||||
| 114 | 2 | return $self->{fields}->{$field}->value; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head2 getKeys | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Returns the list of PR fields contained in the object. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub getKeys { | ||||||||||||||||||||||||||
|
Subroutine
getKeys: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | return keys %{shift->{fields}}; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head2 getNumber | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Returns the gnats PR number. In previous versions of gnatsperl the | ||||||||||||||||||||||||||||
| 130 | Number field was explicitly known to Net::Gnats::PR. This method | ||||||||||||||||||||||||||||
| 131 | remains for backwards compatibility. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | DEPRECATION NOTICE: this will be deprecated in the near future. Use | ||||||||||||||||||||||||||||
| 134 | instead: | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | $r->get_field('Number')->value | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 1 | ▶ | sub getNumber { | ||||||||||||||||||||||||||
|
Subroutine
getNumber: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 1 | return shift->{fields}->{'Number'}->value; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 add_field | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Adds a field instance to the fieldlist of a Nets::Gnats::PR object for fields that are not header fields. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =cut | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 247 | ▶ | sub add_field { | ||||||||||||||||||||||||||
|
Subroutine
add_field: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 247 | my ($self, $field) = @_; | |||||||||||||||||||||||||||
| 153 | 247 | $self->{fields}->{$field->name} = $field; | |||||||||||||||||||||||||||
| 154 | # manage the list of fields in order only if it's not a header field. | ||||||||||||||||||||||||||||
| 155 | 247 | ▶ | unless (_is_header_field($field->name)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 142 | push @{ $self->{fieldlist} }, $field->name; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 247 | return; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head2 get_field | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Returns a field instance of an Nets::Gnats::PR object if field instance is defined. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 306 | ▶ | sub get_field { | ||||||||||||||||||||||||||
|
Subroutine
get_field: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 306 | my ($self, $fieldname) = @_; | |||||||||||||||||||||||||||
| 169 | 306 | ▶ | return $self->{fields}->{$fieldname} if defined $self->{fields}->{$fieldname}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 118 | return undef; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head2 get_field_from | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Return an anonymous array of Nets::Gnats::PR object fields instances from a word part match. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub get_field_from { | ||||||||||||||||||||||||||
|
Subroutine
get_field_from: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 0 | my ( $self, $fieldname) = @_; | |||||||||||||||||||||||||||
| 182 | 0 | my $result = []; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | foreach my $field ( sort keys %{ $self->{fields} } ) { | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | push @$result, $field if $field =~ qr/^$fieldname/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | return $result; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head2 replaceField | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Sets a new value for an existing field. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | If the field requires a Change Reason, and the field does not exist in | ||||||||||||||||||||||||||||
| 196 | the PR, then the FieldInstance for the Change Reason is created. | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Returns 0 if the field does not exist. | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | Returns 0 if the field requires a changeReason, but one was not provided. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | Returns 0 if the change did not occur successfully. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | Returns 1 if the field is set and flushed to Gnats. | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 5 | ▶ | sub replaceField { | ||||||||||||||||||||||||||
|
Subroutine
replaceField: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 209 | 5 | my ($self, $name, $value, $reason_value) = @_; | |||||||||||||||||||||||||||
| 210 | 5 | ▶ | return 0 if not defined $self->get_field($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 5 | ▶ | return 0 if not $self->setField($name, $value, $reason_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 5 | my $f = $self->get_field($name); | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 5 | ▶ | if ($f->schema->requires_change_reason) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 3 | return Net::Gnats | |||||||||||||||||||||||||||
| 217 | ->current_session | ||||||||||||||||||||||||||||
| 218 | ->issue(Net::Gnats::Command->repl( | ||||||||||||||||||||||||||||
| 219 | pr_number => $self->get_field('Number')->value, | ||||||||||||||||||||||||||||
| 220 | field => $f, | ||||||||||||||||||||||||||||
| 221 | field_change_reason => $self->get_field($name . '-Changed-Why'))) | ||||||||||||||||||||||||||||
| 222 | ->is_ok; | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 2 | return Net::Gnats | |||||||||||||||||||||||||||
| 225 | ->current_session | ||||||||||||||||||||||||||||
| 226 | ->issue(Net::Gnats::Command->repl(pr_number => $self->get_field('Number')->value, | ||||||||||||||||||||||||||||
| 227 | field => $f))->is_ok; | ||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =head2 setField | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | Sets a Gnats field value. Expects two arguments: the field name | ||||||||||||||||||||||||||||
| 234 | followed by the field value. If the field requires a change reason, | ||||||||||||||||||||||||||||
| 235 | provide it as a third argument. | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 52 | ▶ | sub setField { | ||||||||||||||||||||||||||
|
Subroutine
setField: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | 52 | my ($self, $name, $value, $reason_value) = @_; | |||||||||||||||||||||||||||
| 241 | 52 | ▶ | return 0 if not defined $self->get_field($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 23 | my $f = $self->get_field($name); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 23 | ▶ | if ($f->schema->requires_change_reason) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 6 | ▶ | return 0 if (not defined $reason_value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 5 | my $cr_instance = | |||||||||||||||||||||||||||
| 247 | Net::Gnats::FieldInstance->new( | ||||||||||||||||||||||||||||
| 248 | schema => $f->schema->change_reason_field($name)); | ||||||||||||||||||||||||||||
| 249 | 5 | $cr_instance->value($reason_value); | |||||||||||||||||||||||||||
| 250 | 5 | $self->add_field($cr_instance); | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 22 | $f->value($value); | |||||||||||||||||||||||||||
| 254 | 22 | return 1; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =head2 submit | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | Submit this PR to Gnats. It uses the currently active session to | ||||||||||||||||||||||||||||
| 260 | perform the submit. | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | $pr = $pr->submit; | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | After a successful submit, the PR with the PR Number is returned. | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | say 'My new number is: ' . $pr->get_field('Number')->value; | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | By default, submit will not send a PR which already has a PR Number. | ||||||||||||||||||||||||||||
| 269 | If your intent is to create a new PR based on this one, use the force | ||||||||||||||||||||||||||||
| 270 | option (may change in the future). This is useful when a series of | ||||||||||||||||||||||||||||
| 271 | similar PRs need to be submitted. | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | $pr = $pr->submit(1); | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | If the PR submission based on force was not successful, the PR will | ||||||||||||||||||||||||||||
| 276 | return with the same PR Number. | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 3 | ▶ | sub submit { | ||||||||||||||||||||||||||
|
Subroutine
submit: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 281 | 3 | my ($self, $force) = @_; | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 3 | ▶ | return $self if defined $self->get_field('Number') and not defined $force; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->get_field("Number") and not defined $force
MC/DC100%2/2
defined $self->get_field("Number") and not defined $force
defined $self->get_field("Number")
not defined $force
Truth table100%3/3
A and not(B)
A= defined $self->get_field("Number")B= not defined $force
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 2 | my $command = Net::Gnats | |||||||||||||||||||||||||||
| 286 | ->current_session | ||||||||||||||||||||||||||||
| 287 | ->issue(Net::Gnats::Command->subm(pr => $self)); | ||||||||||||||||||||||||||||
| 288 | 2 | ▶ | return $self if $command->is_ok == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # the number is in the second response item. This should probably be in SUBM.pm. | ||||||||||||||||||||||||||||
| 291 | 2 | my $number = @{ $command->response->as_list }[1]; | |||||||||||||||||||||||||||
| 292 | 2 | ▶ | if ( $self->get_field('Number') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 1 | $self->get_field('Number')->value($number); | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | else { | ||||||||||||||||||||||||||||
| 296 | 1 | my $field_schema = Net::Gnats->current_session->schema->field('Number'); | |||||||||||||||||||||||||||
| 297 | 1 | $self->add_field(Net::Gnats::FieldInstance->new( name => 'Number', | |||||||||||||||||||||||||||
| 298 | value => $number, | ||||||||||||||||||||||||||||
| 299 | schema => $field_schema )); | ||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | 2 | return $self; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =head2 split_csl | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | Split comma-separated list. | ||||||||||||||||||||||||||||
| 307 | Commas in quotes are not separators! | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub split_csl { | ||||||||||||||||||||||||||
|
Subroutine
split_csl: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 0 | my ($list) = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | # Substitute commas in quotes with \002. | ||||||||||||||||||||||||||||
| 315 | 0 | ▶ | while ($list =~ m~"([^"]*)"~g) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||
| 317 | 0 | my $pos = pos($list); | |||||||||||||||||||||||||||
| 318 | 0 | my $str = $1; | |||||||||||||||||||||||||||
| 319 | 0 | $str =~ s~,~\002~g; | |||||||||||||||||||||||||||
| 320 | 0 | $list =~ s~"[^"]*"~"$str"~; | |||||||||||||||||||||||||||
| 321 | 0 | pos($list) = $pos; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my @res; | |||||||||||||||||||||||||||
| 325 | 0 | foreach my $person (split(/\s*,\s*/, $list)) | |||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||
| 327 | 0 | $person =~ s/\002/,/g; | |||||||||||||||||||||||||||
| 328 | 0 | ▶ | push(@res, $person) if $person; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | 0 | return @res; | |||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =head2 fix_email_addrs | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | Trim email addresses as they appear in an email From or Reply-To | ||||||||||||||||||||||||||||
| 336 | header into a comma separated list of just the addresses. | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | Delete everything inside ()'s and outside <>'s, inclusive. | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | =cut | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | sub fix_email_addrs | ||||||||||||||||||||||||||||
| 343 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
fix_email_addrs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 344 | 0 | my $addrs = shift; | |||||||||||||||||||||||||||
| 345 | 0 | my @addrs = split_csl ($addrs); | |||||||||||||||||||||||||||
| 346 | 0 | my @trimmed_addrs; | |||||||||||||||||||||||||||
| 347 | my $addr; | ||||||||||||||||||||||||||||
| 348 | 0 | foreach $addr (@addrs) | |||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||
| 350 | 0 | $addr =~ s/\(.*\)//; | |||||||||||||||||||||||||||
| 351 | 0 | $addr =~ s/.*<(.*)>.*/$1/; | |||||||||||||||||||||||||||
| 352 | 0 | $addr =~ s/^\s+//; | |||||||||||||||||||||||||||
| 353 | 0 | $addr =~ s/\s+$//; | |||||||||||||||||||||||||||
| 354 | 0 | push(@trimmed_addrs, $addr); | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | 0 | $addrs = join(', ', @trimmed_addrs); | |||||||||||||||||||||||||||
| 357 | 0 | $addrs; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =head2 parse_line | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | Breaks down a Gnats query result. | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =cut | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 210 | ▶ | sub parse_line { | ||||||||||||||||||||||||||
|
Subroutine
parse_line: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 367 | 210 | my ( $line, $known ) = @_; | |||||||||||||||||||||||||||
| 368 | 210 | my $result = []; | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 210 | ▶ | if (_is_header_line($line)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 96 | my @found = $line =~ /^([\w\-\{\}]+):\s*(.*)$/; | |||||||||||||||||||||||||||
| 372 | 96 | return \@found; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 114 | my @found = $line =~ /^>([\w\-\{\d\}]+):\s*(.*)$/; | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 114 | ▶ | if ( not defined $found[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 32 | @{ $result }[1] = $line; | |||||||||||||||||||||||||||
| 379 | 32 | return $result; | |||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 82 | my $schemaname = _schema_fieldname($found[0]); | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 82 | my $schema_found = grep { $_ eq $schemaname } @{ $known }; | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 82 | ▶ | if ( $schema_found == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 1 | @{ $result }[1] = $line; | |||||||||||||||||||||||||||
| 388 | 1 | return $result; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 81 | @{ $result }[0] = $found[0]; | |||||||||||||||||||||||||||
| 392 | 81 | $found[1] =~ s/\s+$//; | |||||||||||||||||||||||||||
| 393 | 81 | @{ $result }[1] = $found[1]; | |||||||||||||||||||||||||||
| 394 | 81 | return $result; | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 159 | ▶ | sub _schema_fieldname { | ||||||||||||||||||||||||||
|
Subroutine
_schema_fieldname: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 398 | 159 | my ( $fieldname ) = @_; | |||||||||||||||||||||||||||
| 399 | 159 | my $schemaname = $fieldname; | |||||||||||||||||||||||||||
| 400 | 159 | $schemaname =~ s/{\d+}$//; | |||||||||||||||||||||||||||
| 401 | 159 | return $schemaname; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 77 | ▶ | sub _schema_fieldinstance { | ||||||||||||||||||||||||||
|
Subroutine
_schema_fieldinstance: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 405 | 77 | my ( $self, $fieldname ) = @_; | |||||||||||||||||||||||||||
| 406 | 77 | return Net::Gnats->current_session | |||||||||||||||||||||||||||
| 407 | ->schema | ||||||||||||||||||||||||||||
| 408 | ->field(_schema_fieldname($fieldname)) | ||||||||||||||||||||||||||||
| 409 | ->instance( for_name => $fieldname ); | ||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 220 | ▶ | sub _clean { | ||||||||||||||||||||||||||
|
Subroutine
_clean: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 413 | 220 | my ( $self, $line ) = @_; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ( not defined $line ) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 220 | $line =~ s/\r|\n//gsm; | |||||||||||||||||||||||||||
| 417 | # $line =~ s/^[.][.]/./gsm; | ||||||||||||||||||||||||||||
| 418 | 220 | return $line; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 377 | ▶ | sub _is_header_line { | ||||||||||||||||||||||||||
|
Subroutine
_is_header_line: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 422 | 377 | my ( $line ) = @_; | |||||||||||||||||||||||||||
| 423 | 377 | ▶ | return 1 if $line =~ /^${\(FROM_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | 346 | ▶ | return 1 if $line =~ /^${\(REPLYTO_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 315 | ▶ | return 1 if $line =~ /^${\(TO_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 284 | ▶ | return 1 if $line =~ /^${\(CC_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 253 | ▶ | return 1 if $line =~ /^${\(SUBJECT_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 222 | ▶ | return 1 if $line =~ /^${\(SENDPR_VER_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 429 | 191 | ▶ | return 1 if $line =~ /^${\(NOTIFY_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 191 | return 0; | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 247 | ▶ | sub _is_header_field { | ||||||||||||||||||||||||||
|
Subroutine
_is_header_field: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 434 | 247 | my ( $name ) = @_; | |||||||||||||||||||||||||||
| 435 | 247 | ▶ | return 1 if $name eq FROM_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 232 | ▶ | return 1 if $name eq REPLYTO_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 217 | ▶ | return 1 if $name eq TO_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 202 | ▶ | return 1 if $name eq CC_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 187 | ▶ | return 1 if $name eq SUBJECT_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 172 | ▶ | return 1 if $name eq SENDPR_VER_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 157 | ▶ | return 1 if $name eq NOTIFY_FIELD; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 142 | return 0; | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 167 | ▶ | sub _is_first_line { | ||||||||||||||||||||||||||
|
Subroutine
_is_first_line: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 446 | 167 | my ( $line ) = @_; | |||||||||||||||||||||||||||
| 447 | 167 | ▶ | return 1 if $line =~ /^${\(FROM_FIELD)}:/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 448 | 152 | return 0; | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | =head2 deserialize | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | Deserializes a PR from Gnats and returns a hydrated PR. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | my $pr = Net::Gnats::PR->deserialize(raw => $c->response->raw, | ||||||||||||||||||||||||||||
| 456 | schema => $s->schema); | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 1 | ▶ | sub setFromString { | ||||||||||||||||||||||||||
|
Subroutine
setFromString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 461 | 1 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 462 | # expects just a block of text, so we need to break it out | ||||||||||||||||||||||||||||
| 463 | 1 | $data =~ s/\r//g; | |||||||||||||||||||||||||||
| 464 | 1 | my @lines = split /\n/, $data; | |||||||||||||||||||||||||||
| 465 | 1 | return Net::Gnats::PR->deserialize(data => \@lines, | |||||||||||||||||||||||||||
| 466 | schema => Net::Gnats->current_session->schema); | ||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 15 | ▶ | sub deserialize { | ||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||
| 470 | 15 | my ($self, %options) = @_; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 15 | my $data = $options{data}; | |||||||||||||||||||||||||||
| 473 | 15 | my $schema = $options{schema}; | |||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 15 | my $pr = Net::Gnats::PR->new(); | |||||||||||||||||||||||||||
| 476 | 15 | my $field; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 15 | foreach my $line (@{$options{data}}) { | |||||||||||||||||||||||||||
| 479 | 220 | $line = $self->_clean($line); | |||||||||||||||||||||||||||
| 480 | 220 | ▶ | next if $line eq '' or $line eq '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$line eq "" or $line eq "."
MC/DC100%2/2
$line eq "" or $line eq "."
$line eq ""
$line eq "."
Truth table100%3/3
A or B
A= $line eq ""B= $line eq "."
| |||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 196 | my ( $name, $content ) = @{ parse_line( $line, $schema->fields ) }; | |||||||||||||||||||||||||||
| 483 | 196 | ▶ | next if not defined $name and $content eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $name and $content eq ""
MC/DC0%0/2
not defined $name and $content eq ""
not defined $name
$content eq ""
Truth table66%2/3
not(A) and B
A= not defined $nameB= $content eq ""
| |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 196 | ▶ | if ( defined $name and _is_first_line( $name . ':') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $name and _is_first_line($name . ':')
MC/DC100%2/2
defined $name and _is_first_line($name . ':')
defined $name
_is_first_line($name . ':')
Truth table100%3/3
A and B
A= defined $nameB= _is_first_line($name . ':')
| |||||||||||||||||||||||||||||
| 486 | # put last PR in array, start new PR | ||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 196 | ▶ | if ( defined $name and _is_header_line( $name . ':' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $name and _is_header_line($name . ':')
MC/DC100%2/2
defined $name and _is_header_line($name . ':')
defined $name
_is_header_line($name . ':')
Truth table100%3/3
A and B
A= defined $nameB= _is_header_line($name . ':')
| |||||||||||||||||||||||||||||
| 490 | 90 | $pr->add_field( | |||||||||||||||||||||||||||
| 491 | Net::Gnats::FieldInstance->new( name => $name, | ||||||||||||||||||||||||||||
| 492 | value => $content, | ||||||||||||||||||||||||||||
| 493 | schema => $schema->field($name))); | ||||||||||||||||||||||||||||
| 494 | 90 | next; | |||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | # known header field found, save. | ||||||||||||||||||||||||||||
| 498 | 106 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 77 | $field = $self->_schema_fieldinstance($name); | |||||||||||||||||||||||||||
| 500 | 77 | $field->value($content); | |||||||||||||||||||||||||||
| 501 | 77 | $pr->add_field($field); | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | # known header field not found, append to last. | ||||||||||||||||||||||||||||
| 504 | else { | ||||||||||||||||||||||||||||
| 505 | 29 | $field->value( $field->value . "\n" . $content ); | |||||||||||||||||||||||||||
| 506 | 29 | $pr->setField($field); | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 15 | ▶ | $pr->get_field('Reply-To')->value($pr->get_field('From')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | if not defined $pr->get_field('Reply-To')->value; | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | # create X-GNATS-Notify if we did not receive it. | ||||||||||||||||||||||||||||
| 515 | 15 | ▶ | if (not defined $pr->get_field('X-GNATS-Notify')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | 15 | $pr->add_field(Net::Gnats::FieldInstance->new( name => 'X-GNATS-Notify', | |||||||||||||||||||||||||||
| 517 | value => '' )); | ||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | # Create an Unformatted field if it doesn't come in from Gnats. | ||||||||||||||||||||||||||||
| 521 | 15 | ▶ | if (not $pr->get_field($UNFORMATTED_FIELD)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | 11 | $pr->add_field(Net::Gnats::FieldInstance->new( name => $UNFORMATTED_FIELD, | |||||||||||||||||||||||||||
| 523 | value => '' )); | ||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 15 | my @attachments = split /$attachment_delimiter/, | |||||||||||||||||||||||||||
| 527 | $pr->get_field($UNFORMATTED_FIELD)->value; | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 15 | ▶ | return $pr if scalar ( @attachments ) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | # First element is any random text which precedes delimited attachments. | ||||||||||||||||||||||||||||
| 532 | 2 | $pr->get_field($UNFORMATTED_FIELD)->value( shift @attachments ); | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 2 | foreach my $attachment (@attachments) { | |||||||||||||||||||||||||||
| 535 | # encoded PR always has a space in front of it | ||||||||||||||||||||||||||||
| 536 | 3 | push @{$pr->{attachments}}, | |||||||||||||||||||||||||||
| 537 | Net::Gnats::Attachment->new( payload => $attachment ); | ||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 2 | return $pr; | |||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | # unparse - | ||||||||||||||||||||||||||||
| 544 | # Turn PR fields hash into a multi-line string. | ||||||||||||||||||||||||||||
| 545 | # | ||||||||||||||||||||||||||||
| 546 | # The $purpose arg controls how things are done. The possible values | ||||||||||||||||||||||||||||
| 547 | # are: | ||||||||||||||||||||||||||||
| 548 | # 'gnatsd' - PR will be filed using gnatsd; proper '.' escaping done | ||||||||||||||||||||||||||||
| 549 | # 'send' - PR will be field using gnatsd, and is an initial PR. | ||||||||||||||||||||||||||||
| 550 | # 'test' - we're being called from the regression tests | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | # What is the user from the session? Need to have user passed for originator. | ||||||||||||||||||||||||||||
| 553 | 7 | ▶ | sub serialize { | ||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 554 | 7 | my ( $self, $pr, $user ) = @_; | |||||||||||||||||||||||||||
| 555 | 7 | ▶ | my $purpose ||= 'gnatsd'; | ||||||||||||||||||||||||||
|
Condition50%1/2
my $purpose ||= "gnatsd"
MC/DC0%0/1
my $purpose ||= "gnatsd"
my $purpose
Truth table50%1/2
A
A= my $purpose
| |||||||||||||||||||||||||||||
| 556 | 7 | ▶ | $user ||= 'bugs'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$user ||= "bugs"
MC/DC0%0/1
$user ||= "bugs"
$user
Truth table50%1/2
A
A= $user
| |||||||||||||||||||||||||||||
| 557 | 7 | my ( $tmp, $text ); | |||||||||||||||||||||||||||
| 558 | 7 | my $debug = 0; | |||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | # First create or reconstruct the Unformatted field containing the | ||||||||||||||||||||||||||||
| 561 | # attachments, if any. | ||||||||||||||||||||||||||||
| 562 | 7 | my %fields = %{$pr->{fields}}; | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | #if (not defined $pr->get_field('Unformatted')) { | ||||||||||||||||||||||||||||
| 565 | # $pr->add_field(Net::Gnats::FieldInstance->new( name => $UNFORMATTED_FIELD, | ||||||||||||||||||||||||||||
| 566 | # value => '', | ||||||||||||||||||||||||||||
| 567 | # schema => )); | ||||||||||||||||||||||||||||
| 568 | #} | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | # deal with attachment later | ||||||||||||||||||||||||||||
| 571 | # my $array_ref = $fields{'attachments'}; | ||||||||||||||||||||||||||||
| 572 | # foreach my $hash_ref (@$array_ref) { | ||||||||||||||||||||||||||||
| 573 | # my $attachment_data = $$hash_ref{'original_attachment'}; | ||||||||||||||||||||||||||||
| 574 | # # Deleted attachments leave empty hashes behind. | ||||||||||||||||||||||||||||
| 575 | # next unless defined($attachment_data); | ||||||||||||||||||||||||||||
| 576 | # $fields{$UNFORMATTED_FIELD} .= $attachment_delimiter . $attachment_data . "\n"; | ||||||||||||||||||||||||||||
| 577 | # } | ||||||||||||||||||||||||||||
| 578 | # warn "unparsepr 2 =>$fields{$UNFORMATTED_FIELD}<=\n" if $debug; | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | # Headers are necessary because Gnats expects it. | ||||||||||||||||||||||||||||
| 581 | 7 | $text .= FROM_FIELD . ': ' . $user . "\n"; | |||||||||||||||||||||||||||
| 582 | 7 | $text .= REPLYTO_FIELD . ': ' . $user . "\n"; | |||||||||||||||||||||||||||
| 583 | 7 | $text .= TO_FIELD . ': bugs' . "\n"; | |||||||||||||||||||||||||||
| 584 | 7 | $text .= CC_FIELD . ': ' . "\n"; | |||||||||||||||||||||||||||
| 585 | 7 | $text .= SUBJECT_FIELD . ': ' . $pr->get_field($SYNOPSIS_FIELD)->value . "\n"; | |||||||||||||||||||||||||||
| 586 | 7 | $text .= SENDPR_VER_FIELD . ': Net::Gnats ' . $Net::Gnats::VERSION . "\n"; | |||||||||||||||||||||||||||
| 587 | 7 | $text .= "\n"; | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 7 | foreach my $fn (@{ $pr->{fieldlist} } ) { | |||||||||||||||||||||||||||
| 590 | 68 | my $field = $pr->get_field($fn); | |||||||||||||||||||||||||||
| 591 | #next if /^.$/; | ||||||||||||||||||||||||||||
| 592 | #next if (not defined($fields{$_})); # Don't send fields that aren't defined. | ||||||||||||||||||||||||||||
| 593 | # Do include Unformatted field in 'send' operation, even though | ||||||||||||||||||||||||||||
| 594 | # it's excluded. We need it to hold the file attachment. | ||||||||||||||||||||||||||||
| 595 | # XXX ??? !!! FIXME | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | # if(($purpose eq 'send') | ||||||||||||||||||||||||||||
| 598 | # && (! ($self->{__gnatsObj}->getFieldTypeInfo ($_, 'flags') & $SENDINCLUDE)) | ||||||||||||||||||||||||||||
| 599 | # && ($_ ne $UNFORMATTED_FIELD)) | ||||||||||||||||||||||||||||
| 600 | # { | ||||||||||||||||||||||||||||
| 601 | # next; | ||||||||||||||||||||||||||||
| 602 | # } | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 68 | ▶ | if ($fn eq 'Unformatted') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 605 | 7 | next; | |||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | # $fields{$_} ||= ''; # Default to empty | ||||||||||||||||||||||||||||
| 608 | 61 | ▶ | if ( $field->schema->type eq 'MultiText' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 14 | $tmp = $field->value; | |||||||||||||||||||||||||||
| 610 | 14 | $tmp =~ s/\r//; | |||||||||||||||||||||||||||
| 611 | 14 | $tmp =~ s/^[.]/../gm; | |||||||||||||||||||||||||||
| 612 | 14 | chomp($tmp); | |||||||||||||||||||||||||||
| 613 | 14 | $text .= sprintf(">%s:\n%s\n", $field->name, $tmp); | |||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | else { | ||||||||||||||||||||||||||||
| 616 | # Format string derived from gnats/pr.c. | ||||||||||||||||||||||||||||
| 617 | 47 | $text .= sprintf("%-16s %s\n", '>' . $field->name . ':', $field->value); | |||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | 61 | ▶ | if ($pr->get_field($field->name . '-Changed-Why')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | # Lines which begin with a '.' need to be escaped by another '.' | ||||||||||||||||||||||||||||
| 622 | # if we're feeding it to gnatsd. | ||||||||||||||||||||||||||||
| 623 | 0 | $tmp = $pr->get_field($_ . '-Changed-Why')->value; | |||||||||||||||||||||||||||
| 624 | 0 | $tmp =~ s/^[.]/../gm; | |||||||||||||||||||||||||||
| 625 | 0 | $text .= sprintf(">%s-Changed-Why:\n%s\n", $field->name, $tmp); | |||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||
| 628 | 7 | $text =~ s/\r//; | |||||||||||||||||||||||||||
| 629 | 7 | return $text; | |||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | # preloaded methods go here. | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 40 | 1; | |||||||||||||||||||||||||||
| 638 | __END__ | ||||||||||||||||||||||||||||