Assert-Conditional
view release on metacpan or search on metacpan
lib/Assert/Conditional/Utils.pm view on Meta::CPAN
@_Map_name2num {@sig_names} = @sig_nums;
sub sig_num2name($)
:Export( sigmappers )
{
my($num) = @_;
$num =~ /^\d+$/ || botch "$num doesn't look like a signal number";
return $_Map_num2name{$num} // botch_undef;
}
sub sig_num2longname($)
:Export( sigmappers )
{
return q(SIG) . &sig_num2name;
}
sub sig_name2num($)
:Export( sigmappers )
{
my($name) = @_;
$name =~ /^\p{upper}+$/ || botch "$name doesn't look like a signal name";
$name =~ s/^SIG//;
return $_Map_name2num{$name} // botch_undef;
}
}
#################################################################
# You really don't want to be looking here.
BEGIN {
package # so PAUSE doesn't index this
Acme::Plural::pl_simple;
require Tie::Hash;
our @ISA = qw(Acme::Plural Tie::StdHash);
sub TIEHASH {
my($class, @args) = @_;
my $self = { };
bless $self, $class;
return $self;
}
sub FETCH {
my($self, $key) = @_;
my($noun, $count) = (split($; => $key), 2);
return $noun if $count eq '1';
$self->{$noun} ||= $self->_lame_plural($noun);
}
}
BEGIN {
package # so PAUSE doesn't index this
Acme::Plural::pl_count;
our @ISA = 'Acme::Plural::pl_simple';
sub FETCH {
my($self, $key) = @_;
my $several = $self->SUPER::FETCH($key);
my($noun, $count) = (split($; => $key), 2);
return "$count $several";
}
}
BEGIN {
package # so PAUSE doesn't index this
Acme::Plural;
use Exporter 'import';
our @EXPORT = qw(
%PLURAL
%N_PLURAL
);
# TODO: replace with the Lingua::EN::Inflect
sub _lame_plural($$) {
my($self, $str) = @_;
return $str if $str =~ s/(?<! [aeiou] ) y $/ies/x;
return $str if $str =~ s/ (?: [szx] | [sc]h ) \K $/es/x;
return $str . "s";
}
tie our %PLURAL => "Acme::Plural::pl_simple";
tie our %N_PLURAL => "Acme::Plural::pl_count";
}
_init_public_vars();
1;
__END__
=encoding utf8
=head1 NAME
Assert::Conditional::Utils - Utility functions for conditionally-compiled assertions
=head1 SYNOPSIS
use Assert::Conditional::Utils qw(panic NOT_REACHED);
$big > $little
|| panic("Impossible for $big > $little");
chdir("/")
|| panic("Your root filesystem is corrupt: $!");
if ($x) { ... }
elsif ($y) { ... }
elsif ($z) { ... }
else { NOT_REACHED }
=head1 DESCRIPTION
This module is used by the L<Assert::Conditional> module for most of the
non-assert functions it needs. Because this module is still in alpha
( run in 0.547 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )