forked from kentnl/MooseX-AttributeIndexes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b31aace
commit 25aed56
Showing
11 changed files
with
157 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 18 additions & 2 deletions
20
lib/MooseX/AttributeIndexes/Meta/Attribute/Trait/Indexed.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,43 @@ | ||
use strict; | ||
use warnings; | ||
package MooseX::AttributeIndexes::Provider::FromAttributes; | ||
|
||
# ABSTRACT: A Glue-on-role that provides attribute_indexes data to a class via harvesting attribute traits | ||
|
||
# $Id:$ | ||
use strict; | ||
use warnings; | ||
use Moose; | ||
use Moose::Role; | ||
use namespace::autoclean; | ||
|
||
=head1 METHODS | ||
=head2 attribute_indexes | ||
A very trivial scanner, which looks for the | ||
C<indexed> and C<primary_index> keys and returns a hashref of | ||
key->value pairs ( circumventing the getter ) | ||
=cut | ||
|
||
sub attribute_indexes { | ||
|
||
my $self = shift; | ||
my $meta = $self->meta(); | ||
|
||
my $k = {}; | ||
|
||
my $map = $meta->get_attribute_map; | ||
for my $attr_name ( keys %{ $map } ){ | ||
my $attr = $map->{$attr_name}; | ||
|
||
if( $attr->does( 'MooseX::AttributeIndexes::Meta::Attribute::Trait::Indexed' ) ) { | ||
if( $attr->indexed || $attr->primary_index ){ | ||
$k->{$attr_name} = $attr->get_value($self); | ||
} | ||
} | ||
} | ||
return $k; | ||
} | ||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval] | ||
allow_includes = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 5; | ||
use Test::Moose; | ||
|
||
use lib 't/lib'; | ||
use Example; | ||
|
||
meta_ok('Example'); | ||
does_ok( 'Example', 'MooseX::AttributeIndexes::Provider' ); | ||
does_ok( 'Example', 'MooseX::AttributeIndexes::Provider::FromAttributes' ); | ||
|
||
my $i = new_ok('Example',[ | ||
foo_indexed => "hello", | ||
foo_nothing => "world", | ||
foo_primary => "bar", | ||
]); | ||
|
||
use Data::Dump qw( dump ); | ||
is_deeply( $i->attribute_indexes, { 'foo_indexed' => 'hello', 'foo_primary' => 'bar' } ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package Example; | ||
|
||
# $Id:$ | ||
use Moose; | ||
|
||
use MooseX::AttributeIndexes; | ||
use namespace::autoclean; | ||
has 'foo_indexed' => ( | ||
isa => 'Str', | ||
required => 1, | ||
is => 'rw', | ||
indexed => 1, | ||
); | ||
|
||
has 'foo_primary' => ( | ||
isa => 'Str', | ||
required => 1, | ||
is => 'rw', | ||
primary_index => 1, | ||
); | ||
|
||
has 'foo_nothing' => ( | ||
isa => 'Str', | ||
required => 1, | ||
is => 'rw', | ||
); | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::Perl::Critic( -profile => 'perlcriticrc' ); | ||
all_critic_ok(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Test::Kwalitee; | ||
|
||
|
||
|