| 1 | # ABSTRACT: Show or change stack properties | ||||||||||
| 2 | |||||||||||
| 3 | package Pinto::Action::Props; | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooseX::StrictConstructor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use MooseX::Types::Moose qw(Str HashRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use String::Format qw(stringf); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Pinto::Constants qw(:color); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Pinto::Util qw(is_system_prop); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Pinto::Types qw(StackName StackDefault StackObject); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | #------------------------------------------------------------------------------ | ||||||||||
| 17 | |||||||||||
| 18 | 1 | our $VERSION = '0.14'; # VERSION | |||||||||
| 19 | |||||||||||
| 20 | #------------------------------------------------------------------------------ | ||||||||||
| 21 | |||||||||||
| 22 | 1 | extends qw( Pinto::Action ); | |||||||||
| 23 | |||||||||||
| 24 | #------------------------------------------------------------------------------ | ||||||||||
| 25 | |||||||||||
| 26 | 1 | with qw( Pinto::Role::Transactional ); | |||||||||
| 27 | |||||||||||
| 28 | #------------------------------------------------------------------------------ | ||||||||||
| 29 | |||||||||||
| 30 | 1 | has stack => ( | |||||||||
| 31 | is => 'ro', | ||||||||||
| 32 | isa => StackName | StackDefault | StackObject, | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | 1 | has properties => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | isa => HashRef, | ||||||||||
| 38 | predicate => 'has_properties', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | 1 | has format => ( | |||||||||
| 42 | is => 'ro', | ||||||||||
| 43 | isa => Str, | ||||||||||
| 44 | default => "%p = %v", | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | #------------------------------------------------------------------------------ | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=2 SCAR=17.9
| |||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||
| 51 | |||||||||||
| 52 | 0 | my $stack = $self->repo->get_stack( $self->stack ); | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | $self->has_properties | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | ? $self->_set_properties($stack) | ||||||||||
| 56 | : $self->_show_properties($stack); | ||||||||||
| 57 | |||||||||||
| 58 | 0 | return $self->result; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | #------------------------------------------------------------------------------ | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub _set_properties { | ||||||||
|
Subroutine
_set_properties: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | 0 | my ( $self, $target ) = @_; | |||||||||
| 65 | |||||||||||
| 66 | 0 | $target->set_properties( $self->properties ); | |||||||||
| 67 | |||||||||||
| 68 | 0 | $self->result->changed; | |||||||||
| 69 | |||||||||||
| 70 | 0 | return; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | #------------------------------------------------------------------------------ | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub _show_properties { | ||||||||
|
Subroutine
_show_properties: not called CC=3 SCAR=24.8
| |||||||||||
| 76 | 0 | my ( $self, $target ) = @_; | |||||||||
| 77 | |||||||||||
| 78 | 0 | my $props = $target->get_properties; | |||||||||
| 79 | 0 | ▶ | while ( my ( $prop, $value ) = each %{$props} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 0 | my $string = stringf( $self->format, { p => $prop, v => $value } ); | |||||||||
| 82 | 0 | ▶ | my $color = is_system_prop($prop) ? $PINTO_PALETTE_COLOR_2 : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | |||||||||||
| 84 | 0 | $self->show( $string, { color => $color } ); | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | #------------------------------------------------------------------------------ | ||||||||||
| 91 | |||||||||||
| 92 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 93 | |||||||||||
| 94 | #------------------------------------------------------------------------------ | ||||||||||
| 95 | |||||||||||
| 96 | 1 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||