#!perl -T ## no critic (TidyCode)

use strict;
use warnings;

use Try::Chain qw( $call_m $fetch_i $fetch_ei $fetch_k $fetch_ek );

our $VERSION = '0.001';
# create an object
sub new {
    return bless {}, __PACKAGE__;
}
# and some methods
sub nothing {
    return;
}
sub string {
    return 'foo';
}
sub list {
    return qw( bar baz );
}
sub array_ref {
    return [ 'item' ];
}
sub hash_ref {
    return { key => 'value' };
}

my $counter = 0;
# prints string
{
    my $result = __PACKAGE__->new->$call_m('string');
    () = print ++$counter, $result || 'undef', "\n";
}
# prints last elemtent of list
{
    my $result = __PACKAGE__->new->$call_m('list');
    () = print ++$counter, $result || 'undef', "\n";
}
# prints value of index
{
    my $result = __PACKAGE__->new->array_ref->$fetch_i(0);
    () = print ++$counter, $result || 'undef', "\n";
}
# prints value of existing index
{
    my $result = __PACKAGE__->new->array_ref->$fetch_ei(0);
    () = print ++$counter, $result || 'undef', "\n";
}
# prints value of key
{
    my $result = __PACKAGE__->new->hash_ref->$fetch_k('key');
    () = print ++$counter, $result || 'undef', "\n";
}
# prints value of existing key
{
    my $result = __PACKAGE__->new->hash_ref->$fetch_ek('key');
    () = print ++$counter, $result || 'undef', "\n";
}

# prints undef because of nothing
{
    my $result = __PACKAGE__->new->nothing->$call_m('string');
    () = print ++$counter, $result || 'undef', "\n";
}
{
    my $result = __PACKAGE__->new->nothing->$call_m('list');
    () = print ++$counter, $result || 'undef', "\n";
}
{
    my $result = __PACKAGE__->new->nothing->$fetch_i(0);
    () = print ++$counter, $result || 'undef', "\n";
}
{
    my $result = __PACKAGE__->new->nothing->$fetch_k('key');
    () = print ++$counter, $result || 'undef', "\n";
}
# prints undef because of not existing
{
    my $result = __PACKAGE__->new->array_ref->$fetch_ei(1);
    () = print ++$counter, $result || 'undef', "\n";
}
{
    my $result = __PACKAGE__->new->hash_ref->$fetch_ek('key1');
    () = print ++$counter, $result || 'undef', "\n";
}

# $Id$

__END__

Output:
1foo
2baz
3item
4item
5value
6value
7undef
8undef
9undef
10undef
11undef
12undef