Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think I've got attribute handlers down for perl Natives!
package tree; has '_branches' => ( traits => ['Hash'], is => 'rw', isa => 'HashRef[Any]', handles => { _set_branch => 'set', _is_branch => 'defined', _list_branches => 'keys', _branch => 'get' }, trigger => sub { my($self,$hash) = @_; $self->_build_branch($hash); } ); sub _build_branch{ my($self,$hash); # do stuff! #return altered or coerced hash return $hash; }
What do you think? But let's say for example I have a LinkedList object with the following methods
LinkedList{} LinkedList.append() LinkedList.insert() LinkedList.size() LinkedList.has_children() LinkedList.remove() LinkedList.split()
Is there a way handle the object's methods via Moose Attributes (without using MooseX) - similar to this?
package Bucket; has '_linkedlist' => ( traits => ['LinkedList'], is => 'rw', isa => 'LinkedListRef[Any]', handles => { _add_link => 'append', _insert_link => 'insert', _count_links => 'size', _del_link => 'remove', _split_at_link => 'split', _has_sublinks => 'has_children', } };
It would be great if there was a way to do this, but I'm concerned maybe I've misunderstood something somewhere about how or why to create handlers for non-native attributes. Your wisdom is appreciated!

In reply to How do you create attribute handlers for methods of an object (via Moose) ? by nodebunny

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-03-19 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found