Honoured bretheren in Perl

I am trying to create a constrained variable using syntax like this ...

use threads; use threads::shared; my $var : shared;
To keep things simple I have created a package called Me providing a 'Me' object. Now I want to be able to do something like this.
use Me; my $user : Me; $user = "Random"; # this is OK $user = "Deterministic"; # croaks

Here is the Me.pm
#!/usr/bin/perl use strict; use warnings; package Me; use Carp; use overload '""' => \&str; sub new { my ($class, $value) = @_; validate ($value) if defined $value; bless \$value, $class; } sub validate { my $value = shift; my @names = qw (Random_Walk Random Walk); croak "$value is not a good name\n" unless grep {$value eq $_} @na +mes; } sub str {"Not telling you"}; 1;
It works fine like this
> perl -Mlib=. -MMe -le'my $m = new Me (Random);print $m' Not telling you > perl -Mlib=. -MMe -le'my $m = new Me (Determined);print $m' Determined is not a good name at -e line 1 # But I can not suss out how to get his to work > perl -Mlib=. -MMe -le'my $m : Me; $m = "Random"; print $m' Invalid SCALAR attribute: Me at -e line 1

I have had a look into attributes and found this Invalid SCALAR attribute? but I remain completely unenlighted how to use this to get the threads::shared syntax working or even if it is possible without delving into XS

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to using an object as a variable type by Random_Walk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.