| 1 | # | ||
| 2 | # This file is part of MooseX-AttributeShortcuts | ||
| 3 | # | ||
| 4 | # This software is Copyright (c) 2017, 2015, 2014, 2013, 2012, 2011 by Chris Weyl. | ||
| 5 | # | ||
| 6 | # This is free software, licensed under: | ||
| 7 | # | ||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||
| 9 | # | ||
| 10 | package MooseX::AttributeShortcuts::Trait::Attribute::HasAnonBuilder; | ||
| 11 | 32 | our $AUTHORITY = 'cpan:RSRCHBOY'; | |
| 12 | 32 | $MooseX::AttributeShortcuts::Trait::Attribute::HasAnonBuilder::VERSION = '0.037'; | |
| 13 | # ABSTRACT: Attributes, etc, common to both the role-attribute and attribute traits | ||
| 14 | |||
| 15 | 32 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 32 | ▶ | use namespace::autoclean 0.24; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | 32 | has anon_builder => ( | |
| 19 | reader => 'anon_builder', | ||
| 20 | writer => '_set_anon_builder', | ||
| 21 | isa => 'CodeRef', | ||
| 22 | predicate => 'has_anon_builder', | ||
| 23 | # init_arg => '_anon_builder', | ||
| 24 | ); | ||
| 25 | |||
| 26 | 32 | has anon_builder_installed => ( | |
| 27 | traits => ['Bool'], | ||
| 28 | is => 'ro', | ||
| 29 | default => 0, | ||
| 30 | handles => { | ||
| 31 | _set_anon_builder_installed => 'set', | ||
| 32 | }, | ||
| 33 | ); | ||
| 34 | |||
| 35 | # FIXME Something Odd keeps this from succeeding as we'd like. | ||
| 36 | #requires 'canonical_builder_prefix'; | ||
| 37 | |||
| 38 | 24 | ▶ | sub _mxas_builder_name { |
|
Subroutine
_mxas_builder_name: called CC=1 SCAR=0.0
| |||
| 39 | 24 | my ($class, $name) = @_; | |
| 40 | |||
| 41 | 24 | return $class->canonical_builder_prefix . $name; | |
| 42 | } | ||
| 43 | |||
| 44 | # this is identical between role and class attributes | ||
| 45 | |||
| 46 | 9 | ▶ | sub _builder_method_meta { |
|
Subroutine
_builder_method_meta: called CC=1 SCAR=0.0
| |||
| 47 | 9 | my ($self, $thing) = @_; | |
| 48 | |||
| 49 | 9 | my $dc = { %{$self->definition_context} }; | |
| 50 | |||
| 51 | $dc->{description} | ||
| 52 | 9 | = 'builder ' . $thing->name . '::' . $self->builder | |
| 53 | . ' of attribute ' . $self->name | ||
| 54 | ; | ||
| 55 | |||
| 56 | 9 | return $self->builder_method_metaclass->wrap($self->anon_builder => | |
| 57 | associated_attribute => $self, | ||
| 58 | associated_metaclass => $thing, | ||
| 59 | name => $self->builder, | ||
| 60 | package_name => $thing->name, | ||
| 61 | definition_context => $dc, | ||
| 62 | ); | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | 32 | !!42; | |
| 67 | |||
| 68 | __END__ | ||