#!/usr/bin/env perl

{
    package Foo;

    use 5.12.0;

    use overload
      '""' => 'stringify',
      '-X' => 'statit';


    sub new {
        my $c = shift;
        bless {@_}, $c;
    }

    sub stringify { $_[0]->{name} }

    sub statit {

	my ( $s, $op ) = ( shift, shift );

	for ( $op ) {

	    when ( 'd' ) { return "Directory: $s" };

	    when ( 'f' ) { return "File: $s" };


	    default { croak( "unsupported file test: -$op: $s\n" ) };


	}

    }

}

{
    package FooNoO;

    use overload
      '""' => 'stringify';

    sub new {
        my $c = shift;
        bless {@_}, $c;
    }

    sub stringify { $_[0]->{name} }

}

use 5.12.0;

my $x = Foo->new( name => 'foo' );

say -d $x;

say "$x";



$x = FooNoO->new( name => '/etc/motd' );

say -f $x;

say "$x";

