File: Named.pm

package info (click to toggle)
libparse-method-signatures-perl 1.003019-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: perl: 3,081; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package Parse::Method::Signatures::Param::Named;

use Moose::Role;
use MooseX::Types::Moose qw/Str/;

use namespace::clean -except => 'meta';

has label => (
    is         => 'ro',
    isa        => Str,
    lazy_build => 1,
);

sub _label_from_variable_name {
    my ($self) = @_;
    # strip sigil
    return substr($self->variable_name, 1);
}

sub _build_label {
    my ($self) = @_;
    return $self->_label_from_variable_name;
}

sub _stringify_required {
    my ($self) = @_;
    return $self->required ? q{!} : q{};
}

around _stringify_variable_name => sub {
    my $orig = shift;
    my ($self) = @_;
    my $ret = q{:};
    my ($before, $after) = (q{}) x 2;

    my $implicit_label = $self->_label_from_variable_name if $self->can('variable_name');

    if (!$implicit_label || $self->label ne $implicit_label) {
        $before = $self->label . q{(};
        $after  = q{)};
    }

    $ret .= $before . $orig->(@_) . $after;

    return $ret;
};

1;