Hydrogen

 view release on metacpan or  search on metacpan

lib/Hydrogen.pm  view on Meta::CPAN

use 5.008001;
use strict;
use warnings;

use List::Util ();
use Scalar::Util ();

package Hydrogen;

our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION   = '0.021002';

use Exporter::Shiny qw( croak fc );

sub croak {
    my ( $message, @args ) = @_;
    if ( @args ) {
        require Data::Dumper;
        local $Data::Dumper::Terse  = 1;
        local $Data::Dumper::Indent = 0;
        $message = sprintf $message, map {
            ref($_) ? Data::Dumper::Dumper($_) : defined($_) ? $_ : '(undef)'
        } @args;
    }
    require Carp;
    @_ = $message;
    goto \&Carp::croak;
}

if ( $] ge '5.016' ) {
    *fc = \&CORE::GLOBAL::fc;
}
else {
   eval 'sub fc { lc( @_ ? $_[0] : $_ ) }';
}

# Compatibility shim for Perl < 5.10
eval 'require re';
unless ( exists &re::is_regexp ) {
    require B;
    *re::is_regexp = sub {
        eval { B::svref_2object( $_[0] )->MAGIC->TYPE eq 'r' };
    };
}

1;

__END__

=pod

=encoding utf-8

=head1 NAME

Hydrogen - utilities for the simplest elements of Perl

=head1 SYNOPSIS

Normal version of the function:

    use feature 'say';
    use Hydrogen::HashRef { prefix => 'hhr_' }, qw( get set );
    
    my %hash;
    hhr_set( \%hash, Alice => 123 );
    hhr_set( \%hash, Bob   => 456 );
    
    say $hash{Alice};                ## ==> 123
    say hhr_get( \%hash, 'Bob' );    ## ==> 456

Version of the function which uses prototypes:

    use feature 'say';
    use Hydrogen::Hash { prefix => 'hh_' }, qw( get set );
    
    my %hash;
    hh_set( %hash, Alice => 123 );
    hh_set( %hash, Bob   => 456 );
    
    say $hash{Alice};                ## ==> 123
    say hh_get( %hash, 'Bob' );      ## ==> 456

Currying:

    use feature 'say';
    use Hydrogen::Curry::HashRef qw( curry_get curry_set );
    
    my %hash;
    my $setter = curry_set( \%hash );



( run in 1.516 second using v1.01-cache-2.11-cpan-8dfa8b56332 )