in reply to Re: RFC: Simulating Python's @decorators in Perl with Attributes
in thread RFC: Simulating Python's @decorators in Perl with Attributes

> ...then syntax like
my %capital : Hash::Sorted;

> would be too cumbersome.

did you ever get this to work? I can't.

I even tried Perl4's quote as separator...

code
use strict; use warnings; use Attribute::Handlers; package H; sub Sorted :ATTR { print "sorted" } package main; my $tst :H::Sorted; sub tst :H::Sorted { print "hui" } tst();
stderr
Invalid separator character ':' in attribute list at /home/lanx/B/PL/P +M/uni_attr.pl line 16, near "$tst :H" syntax error at /home/lanx/B/PL/PM/uni_attr.pl line 16, near "$tst :H" Invalid separator character ':' in attribute list at /home/lanx/B/PL/P +M/uni_attr.pl line 18, near "sub tst :H" syntax error at /home/lanx/B/PL/PM/uni_attr.pl line 18, near "sub tst +:H" Execution of /home/lanx/B/PL/PM/uni_attr.pl aborted due to compilation + errors.

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^3: RFC: Simulating Python's @decorators in Perl with Attributes
by Arunbear (Prior) on Jun 01, 2013 at 14:06 UTC
    Sorry, the verbose syntax example I gave was wrong. It would actually be like this:
    #!/usr/bin/perl use strict; use warnings; package Foo::Sorted; use Attribute::Handlers; sub Sorted :ATTR { print "all sorted" } package main; my Foo::Sorted $tst :Sorted;
      But if you worry about name collision in UNIVERSAL (which isn't my biggest concern) why don't you just import the attribute Sorted into the current package?

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        Importing the attribute does not seem to work:
        # Foo.pm package Foo; use strict; use Attribute::Handlers; use Exporter 'import'; our @EXPORT = qw/Sorted/; sub Sorted :ATTR { print "all sorted" } 1; # attr.pl #!/usr/bin/perl use strict; use warnings; use Foo; my Foo $tst1 :Sorted; my $tst2 :Sorted; print "done\n";
        It dies with
        Invalid SCALAR attribute: Sorted at /home/arun/attr.pl line 8.