| 1 | package Treex::Core::RememberArgs; | ||||||||||
| 2 | 1 | $Treex::Core::RememberArgs::VERSION = '2.20210102'; | |||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | has args => ( | ||||||||||
| 6 | is => 'ro', | ||||||||||
| 7 | isa => 'HashRef', | ||||||||||
| 8 | writer => '_set_args', | ||||||||||
| 9 | 0 | ▶ | default => sub {return {};}, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 10 | 1 | ); | |||||||||
| 11 | |||||||||||
| 12 | 1 | has args_str => ( | |||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | isa => 'Str', | ||||||||||
| 15 | writer => '_set_args_str', | ||||||||||
| 16 | default => '', | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | # Empty BUILD is needed, so we can use "after BUILD". | ||||||||||
| 20 | # "after BUILD" is needed because we cannot (and don't want to) | ||||||||||
| 21 | # override the BUILD which may be present in the class which will consume this role. | ||||||||||
| 22 | # See http://rjbs.manxome.org/rubric/entry/1864 | ||||||||||
| 23 | 0 | ▶ | sub BUILD {} | ||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 0 | ▶ | after BUILD => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||
| 25 | 0 | my ($self, $args) = @_; | |||||||||
| 26 | 0 | $self->_set_args($args); | |||||||||
| 27 | 0 | my $str = ''; | |||||||||
| 28 | |||||||||||
| 29 | # The method which consumes this role may implement | ||||||||||
| 30 | # its BUILD where a default values of some attributes | ||||||||||
| 31 | # are set. Let's put back these values into $args. | ||||||||||
| 32 | 0 | foreach my $key (keys %{$self}) { | |||||||||
| 33 | 0 | ▶ | next if $key =~ /^args(_str)?$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | my $value = $self->{$key}; | |||||||||
| 35 | 0 | ▶ | next if !defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | next if ref $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | $args->{$key} = $value; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # Prepare a single-quoted string representation of all args. | ||||||||||
| 41 | 0 | ▶ | while (my ($key, $value) = each %{$args}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | ▶ | if ($value =~ /\s/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | $value =~ s/'/\\'/g; | |||||||||
| 44 | 0 | $value = "'$value'"; | |||||||||
| 45 | } | ||||||||||
| 46 | 0 | $str .= "$key=$value "; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | $str =~ s/ $//; | |||||||||
| 49 | 0 | $self->_set_args_str($str); | |||||||||
| 50 | 0 | return; | |||||||||
| 51 | 1 | }; | |||||||||
| 52 | |||||||||||
| 53 | 1 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||