MooseX::Role::Hashable - Transform the object into a hash
Version 1.04
This module adds a single method to an object to convert it into a simple hash. This is meant to act as the inverse function of new, provided nothing too crazy is going on during initialization. If the class is made immutable, the optimizer will precalculate the extracted attributes for a signifcant speed up.
Example usage:
package Foo; use Moose; use MooseX::Role::Hashable; has field1 => (is => 'rw'); has field2 => (is => 'ro'); has field3 => (is => 'bare'); has _field4 => (is => 'rw', init_arg => 'field4'); __PACKAGE__->meta->make_immutable; package main; my $foo = Foo->new(field1 => 'val1', field2 => 'val2', field3 => 'val3', field4 => 'val4'); $foo->as_hash; # => {field1 => 'val1', field2 => 'val2', field3 => 'val3', field4 => 'val4'}
Transform the object into a hash of attribute-value pairs. All attributes, including those without a reader, are extracted. Attributes whose initial arguments differ from their name will appear using the initialization argument. Attributes which can' be initialized will be ignored. Reference values will perform a shallow copy.
Aaron Cohen, <aarondcohen at gmail.com>
<aarondcohen at gmail.com>
Special thanks to: Dibin Pookombil
This module was made possible by Shutterstock (@ShutterTech). Additional open source projects from Shutterstock can be found at code.shutterstock.com.
Please report any bugs or feature requests to bug-MooseX-Role-Hashable at rt.cpan.org, or through the web interface at https://github.com/aarondcohen/perl-moosex-role-hashable/issues. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-MooseX-Role-Hashable at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc MooseX::Role::Hashable
You can also look for information at:
Official GitHub Repo
https://github.com/aarondcohen/perl-moosex-role-hashable
GitHub's Issue Tracker (report bugs here)
https://github.com/aarondcohen/perl-moosex-role-hashable/issues
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-Role-Hashable
Official CPAN Page
http://search.cpan.org/dist/MooseX-Role-Hashable/
Copyright 2013,2014 Aaron Cohen.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install MooseX::Role::Hashable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::Hashable
CPAN shell
perl -MCPAN -e shell install MooseX::Role::Hashable
For more information on module installation, please visit the detailed CPAN module installation guide.