From: Dave Rolsky Date: Wed, 20 Jan 2010 21:37:02 +0000 (-0600) Subject: run code through perltidy X-Git-Tag: 0.11~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9b2bd146f5b6820a72cb0b2d0b8ca8d3eee2ad4e;p=gitmo%2FMooseX-ClassAttribute.git run code through perltidy --- diff --git a/lib/MooseX/ClassAttribute.pm b/lib/MooseX/ClassAttribute.pm index d142d41..286fbaa 100644 --- a/lib/MooseX/ClassAttribute.pm +++ b/lib/MooseX/ClassAttribute.pm @@ -3,41 +3,40 @@ package MooseX::ClassAttribute; use strict; use warnings; -our $VERSION = '0.10'; +our $VERSION = '0.10'; our $AUTHORITY = 'cpan:DROLSKY'; use Moose 0.89 (); use Moose::Exporter; use MooseX::ClassAttribute::Role::Meta::Class; -Moose::Exporter->setup_import_methods - ( with_meta => [ 'class_has' ] ); +Moose::Exporter->setup_import_methods( with_meta => ['class_has'] ); - -sub init_meta -{ +sub init_meta { shift; my %p = @_; Moose->init_meta(%p); - return - Moose::Util::MetaRole::apply_metaclass_roles - ( for_class => $p{for_class}, - metaclass_roles => [ 'MooseX::ClassAttribute::Role::Meta::Class' ], - ); + return Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $p{for_class}, + class_metaroles => { + class => ['MooseX::ClassAttribute::Role::Meta::Class'], + }, + role_metaroles => { + role => ['MooseX::ClassAttribute::Role::Meta::Role'], + }, + ); } -sub class_has -{ +sub class_has { my $meta = shift; my $name = shift; my %options = @_; my $attrs = ref $name eq 'ARRAY' ? $name : [$name]; - $meta->add_class_attribute( $_, %options ) - for @{ $attrs }; + $meta->add_class_attribute( $_, %options ) for @{$attrs}; } 1; diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm index eb798a3..7ec220f 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Class.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Class.pm @@ -9,41 +9,40 @@ use Scalar::Util qw( blessed ); use Moose::Role; - -has class_attribute_map => - ( metaclass => 'Collection::Hash', - is => 'ro', - isa => 'HashRef[Moose::Meta::Attribute]', - provides => { set => '_add_class_attribute', - exists => 'has_class_attribute', - get => 'get_class_attribute', - delete => '_remove_class_attribute', - keys => 'get_class_attribute_list', - }, - default => sub { {} }, - reader => 'get_class_attribute_map', - ); - -has _class_attribute_values => - ( metaclass => 'Collection::Hash', - is => 'ro', - isa => 'HashRef', - provides => { get => 'get_class_attribute_value', - set => 'set_class_attribute_value', - exists => 'has_class_attribute_value', - delete => 'clear_class_attribute_value', - }, - lazy => 1, - default => sub { $_[0]->_class_attribute_values_hashref() }, - ); - - -sub add_class_attribute -{ +has class_attribute_map => ( + metaclass => 'Collection::Hash', + is => 'ro', + isa => 'HashRef[Moose::Meta::Attribute]', + provides => { + set => '_add_class_attribute', + exists => 'has_class_attribute', + get => 'get_class_attribute', + delete => '_remove_class_attribute', + keys => 'get_class_attribute_list', + }, + default => sub { {} }, + reader => 'get_class_attribute_map', +); + +has _class_attribute_values => ( + metaclass => 'Collection::Hash', + is => 'ro', + isa => 'HashRef', + provides => { + get => 'get_class_attribute_value', + set => 'set_class_attribute_value', + exists => 'has_class_attribute_value', + delete => 'clear_class_attribute_value', + }, + lazy => 1, + default => sub { $_[0]->_class_attribute_values_hashref() }, +); + +sub add_class_attribute { my $self = shift; - my $attr = - blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') + my $attr + = blessed $_[0] && $_[0]->isa('Class::MOP::Attribute') ? $_[0] : $self->_process_class_attribute(@_); @@ -56,10 +55,13 @@ sub add_class_attribute $self->_add_class_attribute( $name => $attr ); - my $e = do { local $@; eval { $attr->install_accessors() }; $@ }; + my $e = do { + local $@; + eval { $attr->install_accessors() }; + $@; + }; - if ( $e ) - { + if ($e) { $self->remove_attribute($name); die $e; } @@ -70,62 +72,55 @@ sub add_class_attribute # It'd be nice if I didn't have to replicate this for class # attributes, since it's basically just a copy of # Moose::Meta::Class->_process_attribute -sub _process_class_attribute -{ +sub _process_class_attribute { my $self = shift; my $name = shift; my @args = @_; - @args = %{$args[0]} if scalar @args == 1 && ref($args[0]) eq 'HASH'; + @args = %{ $args[0] } if scalar @args == 1 && ref( $args[0] ) eq 'HASH'; - if ($name =~ /^\+(.*)/) - { + if ( $name =~ /^\+(.*)/ ) { return $self->_process_inherited_class_attribute( $1, @args ); } - else - { + else { return $self->_process_new_class_attribute( $name, @args ); } } -sub _process_new_class_attribute -{ +sub _process_new_class_attribute { my $self = shift; my $name = shift; my %p = @_; - if ( $p{traits} ) - { - push @{ $p{traits} },'MooseX::ClassAttribute::Role::Meta::Attribute' + if ( $p{traits} ) { + push @{ $p{traits} }, 'MooseX::ClassAttribute::Role::Meta::Attribute'; } - else - { - $p{traits} = [ 'MooseX::ClassAttribute::Role::Meta::Attribute' ]; + else { + $p{traits} = ['MooseX::ClassAttribute::Role::Meta::Attribute']; } return Moose::Meta::Attribute->interpolate_class_and_new( $name, %p ); } -sub _process_inherited_class_attribute -{ +sub _process_inherited_class_attribute { my $self = shift; my $name = shift; my %p = @_; my $inherited_attr = $self->find_class_attribute_by_name($name); - (defined $inherited_attr) - || confess "Could not find an attribute by the name of '$name' to inherit from"; + ( defined $inherited_attr ) + || confess + "Could not find an attribute by the name of '$name' to inherit from"; return $inherited_attr->clone_and_inherit_options(%p); } -sub remove_class_attribute -{ +sub remove_class_attribute { my $self = shift; my $name = shift; - (defined $name && $name) + ( defined $name && $name ) || confess 'You must provide an attribute name'; my $removed_attr = $self->get_class_attribute($name); @@ -139,79 +134,76 @@ sub remove_class_attribute return $removed_attr; } -sub get_all_class_attributes -{ +sub get_all_class_attributes { my $self = shift; - my %attrs = - map { my $meta = Class::MOP::class_of($_); - $meta && $meta->can('get_class_attribute_map') - ? %{ $meta->get_class_attribute_map() } - : () - } + my %attrs + = map { + my $meta = Class::MOP::class_of($_); + $meta && $meta->can('get_class_attribute_map') + ? %{ $meta->get_class_attribute_map() } + : () + } reverse $self->linearized_isa; return values %attrs; } -sub compute_all_applicable_class_attributes -{ - warn 'The compute_all_applicable_class_attributes method has been deprecated.' +sub compute_all_applicable_class_attributes { + warn + 'The compute_all_applicable_class_attributes method has been deprecated.' . " Use get_all_class_attributes instead.\n"; shift->compute_all_applicable_class_attributes(@_); } -sub find_class_attribute_by_name -{ +sub find_class_attribute_by_name { my $self = shift; my $name = shift; - foreach my $class ( $self->linearized_isa() ) - { + foreach my $class ( $self->linearized_isa() ) { my $meta = Class::MOP::class_of($class) or next; return $meta->get_class_attribute($name) - if $meta->can('has_class_attribute') && $meta->has_class_attribute($name); + if $meta->can('has_class_attribute') + && $meta->has_class_attribute($name); } return; } -sub _class_attribute_values_hashref -{ +sub _class_attribute_values_hashref { my $self = shift; no strict 'refs'; return \%{ $self->_class_attribute_var_name() }; } -sub _class_attribute_var_name -{ +sub _class_attribute_var_name { my $self = shift; return $self->name() . q'::__ClassAttributeValues'; } -sub inline_class_slot_access -{ +sub inline_class_slot_access { my $self = shift; my $name = shift; - return '$' . $self->_class_attribute_var_name . '{"' . quotemeta($name) . '"}'; + return + '$' + . $self->_class_attribute_var_name . '{"' + . quotemeta($name) . '"}'; } -sub inline_get_class_slot_value -{ +sub inline_get_class_slot_value { my $self = shift; my $name = shift; return $self->inline_class_slot_access($name); } -sub inline_set_class_slot_value -{ +sub inline_set_class_slot_value { my $self = shift; my $name = shift; my $val_name = shift; @@ -219,28 +211,27 @@ sub inline_set_class_slot_value return $self->inline_class_slot_access($name) . ' = ' . $val_name; } -sub inline_is_class_slot_initialized -{ - my $self = shift; - my $name = shift; +sub inline_is_class_slot_initialized { + my $self = shift; + my $name = shift; return 'exists ' . $self->inline_class_slot_access($name); } -sub inline_deinitialize_class_slot -{ - my $self = shift; - my $name = shift; +sub inline_deinitialize_class_slot { + my $self = shift; + my $name = shift; return 'delete ' . $self->inline_class_slot_access($name); } -sub inline_weaken_class_slot_value -{ - my $self = shift; - my $name = shift; +sub inline_weaken_class_slot_value { + my $self = shift; + my $name = shift; - return 'Scalar::Util::weaken( ' . $self->inline_class_slot_access($name) . ')'; + return + 'Scalar::Util::weaken( ' + . $self->inline_class_slot_access($name) . ')'; } no Moose::Role;