File: ArgumentCollector.pm

package info (click to toggle)
libextutils-builder-compiler-perl 0.032-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 1,252; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ExtUtils::Builder::ArgumentCollector;
$ExtUtils::Builder::ArgumentCollector::VERSION = '0.032';
use strict;
use warnings;

sub _init {
	my ($self, %args) = @_;
	$self->{arguments} = $args{arguments} // [];
	return;
}

sub add_argument {
	my ($self, %arguments) = @_;
	$arguments{ranking} = $self->fix_ranking(delete @arguments{qw/ranking fix/});
	push @{ $self->{arguments} }, $self->new_argument(%arguments);
	return;
}

sub new_argument {
	my ($self, %args) = @_;
	return [ $args{ranking} // 50, $args{value} ];
}

sub collect_arguments {
	my $self = shift;
	return @{ $self->{arguments} };
}

sub arguments {
	my ($self, @args) = @_;
	use sort 'stable';
	return map { @{ $_->[1] } } sort { $a->[0] <=> $b->[0] } $self->collect_arguments(@args);
}

sub fix_ranking {
	my (undef, $baseline, $override) = @_;
	return $baseline if not defined $override;
	return (ref($override) eq 'CODE') ? $override->($baseline) : $override;
}

1;

=pod

=encoding UTF-8

=head1 NAME

ExtUtils::Builder::ArgumentCollector - Helper role for argument collecting classes

=head1 VERSION

version 0.032

=head1 DESCRIPTION

This is a helper role for classes that collect arguments for their command. Classes that use this include ExtUtils::Builder::Compiler and ExtUtils::Builder::Linker

=head1 AUTHOR

Leon Timmermans <fawaka@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__

#ABSTRACT: Helper role for argument collecting classes