Acme-Crap
view release on metacpan or search on metacpan
lib/Acme/Crap.pm view on Meta::CPAN
package Acme::Crap;
use 5.010;
our $VERSION = '0.001003';
use warnings;
use strict;
use Carp;
sub deref { my ($self) = @_; return ${$self}; }
use overload (
q{!} => sub { Acme::Crap::Negated->new(&deref) },
q{""} => \&deref,
q{0+} => \&deref,
q{bool} => \&deref,
fallback => 1,
);
sub import {
overload::constant q => sub { my $val = $_[1]; bless \$val, 'Acme::Crap' };
no strict qw( refs );
*{caller().'::crap'} = sub {
local $Acme::Crap::no_negation = 1;
@_ = map {"$_"} @_;
goto &Carp::carp;
}
}
package Acme::Crap::Negated;
sub new {
my ($class, $val) = @_;
bless { val => $val, degree => 1 }, $class;
}
sub value {
my ($self) = @_;
if ($Acme::Crap::no_negation) {
return $self->{degree} == 1 ? ucfirst "$self->{val}!"
: $self->{degree} == 2 ? join q{}, map { ucfirst $_ } split /(\s+)/, "$self->{val}!!"
: uc $self->{val} . '!' x $self->{degree};
}
return !$self->{val} if $self->{degree} % 2;
return !!$self->{val};
}
use overload (
q{!} => sub { my ($self) = @_; $self->{degree}++; return $self; },
q{""} => \&value,
q{0+} => \&value,
q{bool} => \&value,
fallback => 1,
);
1; # Magic true value required at end of module
__END__
=head1 NAME
Acme::Crap - Carp with more feeling
=head1 VERSION
This document describes Acme::Crap version 0.001003
=head1 SYNOPSIS
use Acme::Crap;
crap "there was a problem";
crap! "there was a bad problem";
crap!! "there was a really bad problem";
crap!!! "there was a really very bad problem";
=head1 DESCRIPTION
Load the module. Now you can spell C<carp> more scatologically, and with
as many trailing exclamation marks as you need to satisfy your degree of
frustration.
=head1 INTERFACE
Always exports the C<crap> subroutine, which works just like
C<carp> but allows trailing exclamation marks on the sub name,
for emphasis.
=head1 DIAGNOSTICS
None. C<crap> I<is> a diagnostic.
( run in 1.058 second using v1.01-cache-2.11-cpan-39bf76dae61 )