| 1 | package Net::Gnats::Field; | ||||||||||
| 2 | 40 | ▶ | use strictures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 40 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 40 | $Net::Gnats::Field::VERSION = '0.22'; | |||||||||
| 5 | } | ||||||||||
| 6 | 40 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use Net::Gnats::FieldInstance; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Net::Gnats::Field | ||||||||||
| 13 | |||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||
| 15 | |||||||||||
| 16 | Base class for a PR's metadata | ||||||||||
| 17 | |||||||||||
| 18 | In a given session, for a given field, this should have to be run once | ||||||||||
| 19 | and stashed somewhere for reuse. | ||||||||||
| 20 | |||||||||||
| 21 | =head1 EXAMPLES | ||||||||||
| 22 | |||||||||||
| 23 | Construct an empty field | ||||||||||
| 24 | |||||||||||
| 25 | my $f = Net::Gnats::Field->new; | ||||||||||
| 26 | |||||||||||
| 27 | Initialize from server | ||||||||||
| 28 | |||||||||||
| 29 | my $f = Net::Gnats::Field->new( name => 'myfield' )->initialize($session); | ||||||||||
| 30 | |||||||||||
| 31 | Manual initialization | ||||||||||
| 32 | |||||||||||
| 33 | my $f = Net::Gnats::Field | ||||||||||
| 34 | ->new( name => 'myfield', | ||||||||||
| 35 | description => 'description', | ||||||||||
| 36 | type => type, | ||||||||||
| 37 | default => default, | ||||||||||
| 38 | flags => flags, | ||||||||||
| 39 | validators => validators ); | ||||||||||
| 40 | |||||||||||
| 41 | =cut | ||||||||||
| 42 | |||||||||||
| 43 | 915 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||
| 44 | 915 | my ( $class, %o ) = @_; | |||||||||
| 45 | 915 | ▶ | return bless {}, $class if not %o; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | return bless \%o, $class; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 5 | ▶ | sub change_reason_field { | ||||||||
|
Subroutine
change_reason_field: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 50 | 5 | my ( $self, $name ) = @_; | |||||||||
| 51 | 5 | ▶ | return undef if not $self->requires_change_reason; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 5 | ▶ | $self->_create_change_reason($name) if not defined $self->{change_reason}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 5 | return $self->{change_reason}; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1042 | ▶ | sub default { | ||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 57 | 1042 | my ( $self, $value ) = @_; | |||||||||
| 58 | 1042 | ▶ | $self->{default} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 1042 | $self->{default}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 920 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 63 | 920 | my ( $self, $value ) = @_; | |||||||||
| 64 | 920 | ▶ | $self->{description} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 920 | $self->{description}; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 948 | ▶ | sub flags { | ||||||||
|
Subroutine
flags: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 69 | 948 | my ( $self, $value ) = @_; | |||||||||
| 70 | 948 | ▶ | $self->{flags} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 948 | $self->{flags}; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 970 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 75 | 970 | my ( $self, $value ) = @_; | |||||||||
| 76 | 970 | ▶ | $self->{name} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 970 | $self->{name}; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 34 | ▶ | sub requires_change_reason { | ||||||||
|
Subroutine
requires_change_reason: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 81 | 34 | ▶ | return 1 if shift->flags =~ /requireChangeReason/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 19 | return 0; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 978 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 86 | 978 | my ( $self, $value ) = @_; | |||||||||
| 87 | 978 | ▶ | $self->{type} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 978 | $self->{type}; | |||||||||
| 89 | } | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub validators { | ||||||||
|
Subroutine
validators: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 92 | 0 | my ( $self, $value ) = @_; | |||||||||
| 93 | 0 | ▶ | $self->{validators} = $value if defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | $self->{validators}; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | =head1 METHODS | ||||||||||
| 98 | |||||||||||
| 99 | =head2 initialize | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 0 | ▶ | sub initialize { | ||||||||
|
Subroutine
initialize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 104 | 0 | my ( $self ) = @_; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | =head2 instance | ||||||||||
| 108 | |||||||||||
| 109 | Creates an instance of this meta field. Represents a literal field in a PR. | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||
| 113 | 77 | ▶ | sub instance { | ||||||||
|
Subroutine
instance: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||
| 114 | 77 | my ( $self, %options ) = @_; | |||||||||
| 115 | 77 | ▶ | my $name = defined $options{for_name} ? $options{for_name} : $self->name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 77 | my $fi = Net::Gnats::FieldInstance->new( schema => $self, name => $name ); | |||||||||
| 117 | 77 | ▶ | $fi->value( $options{value} ) if defined $options{value}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 77 | return $fi; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 3 | ▶ | sub _create_change_reason { | ||||||||
|
Subroutine
_create_change_reason: called CC=1 SCAR=0.0
| |||||||||||
| 122 | 3 | my ($self, $name) = @_; | |||||||||
| 123 | 3 | my $f = Net::Gnats::Field->new; | |||||||||
| 124 | 3 | $f->name($name . '-Changed-Why'); | |||||||||
| 125 | 3 | $f->description($self->description . ' - Reason for Change'); | |||||||||
| 126 | 3 | $f->type('multiText'); | |||||||||
| 127 | 3 | $self->{change_reason} = $f; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 40 | 1; | |||||||||