| 1 | # You may distribute under the terms of either the GNU General Public License | ||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||
| 3 | # | ||
| 4 | # (C) Paul Evans, 2020-2022 -- leonerd@leonerd.org.uk | ||
| 5 | |||
| 6 | package Object::Pad::MOP::Field 0.825; | ||
| 7 | |||
| 8 | use v5.18; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | # This is an XS-implemented object type provided by Object::Pad itself | ||
| 12 | require Object::Pad; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | C<Object::Pad::MOP::Field> - meta-object representation of data field of a C<Object::Pad> class | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | =for highlighter language=perl | ||
| 21 | |||
| 22 | Instances of this class represent a data field of a class implemented by | ||
| 23 | L<Object::Pad>. Accessors provide information about the field. The special | ||
| 24 | C<value> method allows access to the value of the given field on instances of | ||
| 25 | its class, letting the meta-object be used as a proxy to it. | ||
| 26 | |||
| 27 | This API should be considered B<experimental>, and will emit warnings to that | ||
| 28 | effect. They can be silenced with | ||
| 29 | |||
| 30 | use Object::Pad qw( :experimental(mop) ); | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | =head1 METHODS | ||
| 35 | |||
| 36 | =head2 name | ||
| 37 | |||
| 38 | $name = $metafield->name; | ||
| 39 | |||
| 40 | Returns the name of the field, as a plain string including the leading sigil | ||
| 41 | character. | ||
| 42 | |||
| 43 | =head2 sigil | ||
| 44 | |||
| 45 | $sigil = $metafield->sigil; | ||
| 46 | |||
| 47 | I<Since version 0.56.> | ||
| 48 | |||
| 49 | Returns the first character of the field name, giving just its leading sigil. | ||
| 50 | |||
| 51 | =head2 class | ||
| 52 | |||
| 53 | $metaclass = $metafield->class; | ||
| 54 | |||
| 55 | Returns the L<Object::Pad::MOP::Class> instance representing the class of | ||
| 56 | which this field is a member. | ||
| 57 | |||
| 58 | =head2 value | ||
| 59 | |||
| 60 | $current = $metafield->value( $instance ); | ||
| 61 | @current = $metafield->value( $instance ); | ||
| 62 | %current = $metafield->value( $instance ); | ||
| 63 | |||
| 64 | An accessor method which returns the current value of the field from an object | ||
| 65 | instance. | ||
| 66 | |||
| 67 | $metafield->value( $instance ) = $new; | ||
| 68 | |||
| 69 | On scalar fields, this method can also act as an lvalue mutator allowing a new | ||
| 70 | value to be set. | ||
| 71 | |||
| 72 | =head2 has_attribute | ||
| 73 | |||
| 74 | $exists = $metafield->has_attribute( $name ); | ||
| 75 | |||
| 76 | I<Since version 0.57.> | ||
| 77 | |||
| 78 | Returns a boolean indicating whether the named attribute has been attached to | ||
| 79 | the field. The attribute name should not include the leading colon (C<:>) | ||
| 80 | character. | ||
| 81 | |||
| 82 | =head2 get_attribute_value | ||
| 83 | |||
| 84 | $value = $metafield->get_attribute_value( $name ); | ||
| 85 | |||
| 86 | I<Since version 0.57.> | ||
| 87 | |||
| 88 | Returns the stored value of an attached attribute, if one exists. If the | ||
| 89 | attribute has not been attached then an exception is thrown. | ||
| 90 | |||
| 91 | Note that most core-defined attributes will either store no data at all, or | ||
| 92 | a method name string. This accessor method is provided largely for the benefit | ||
| 93 | of obtaining data defined by third-party attributes, which may more clearly | ||
| 94 | define how that data is generated and used. | ||
| 95 | |||
| 96 | =head2 get_attribute_values | ||
| 97 | |||
| 98 | @values = $metafield->get_attribute_values( $name ); | ||
| 99 | |||
| 100 | I<Since version 0.66.> | ||
| 101 | |||
| 102 | Returns all the stored values of an attached attribute, if one exists. If the | ||
| 103 | attribute has not been attached then an exception is thrown. | ||
| 104 | |||
| 105 | This allows inspection of stored attribute values if it makes meaningful sense | ||
| 106 | for the attribute to be applied multiple times to the same field. This is | ||
| 107 | unlikely to be useful for core-defined attributes, but may be meaningful for | ||
| 108 | third-party attributes. | ||
| 109 | |||
| 110 | =cut | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | Paul Evans <leonerd@leonerd.org.uk> | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | 0x55AA; |