As I understand it, attributes are syntactic sugar to do "stuff". Here's a random simple example:

package Loud; use Attribute::Handlers; sub Loud :ATTR { my ($package, $symbol, $referent, $attr, $data, $phase) = @_; no strict 'refs'; # redefines subroutines given the "Loud" attribute *{$package.'::'.*{$symbol}{NAME}} = sub { # dup STDOUT and instead pipe things to another program open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: +$!"; open STDOUT, "| perl -pe 'tr/a-z/A-Z/'" or die "Can't redirect STD +OUT: $!"; $| = 1; # call the original subroutine $referent->(@_); # restore STDOUT close STDOUT; open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!"; } } # ... in another file or package package main; use base qw/Loud/; # We want this function to be loud sub foo : Loud { print "Purple is a nice color.\n"; } foo(); print "Don't yell!\n";

The output of this program (it runs as shown above) is:

PURPLE IS A NICE COLOR. Don't yell!

Catalyst uses the ActionClass attribute here to append some action (provided by RenderView.pm) to your subroutine

Good Day,
    Dean


In reply to Re: How is this Perl? by duelafn
in thread How is this Perl? by Anonymous Monk

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.