1package Data::Object::Struct;
2
3use 5.014;
4
5use strict;
6use warnings;
7use routines;
8
9use Data::Object::Class;
10
11with 'Data::Object::Role::Buildable';
12with 'Data::Object::Role::Immutable';
13with 'Data::Object::Role::Proxyable';
14
15our $VERSION = '2.00'; # VERSION
16
17method build_self($args) {
18  %$self = %$args;
19
20  $self->immutable;
21
22  return $self;
23}
24
25method build_proxy($package, $method) {
26  return sub { $self->{$method} } if exists $self->{$method};
27
28  return undef;
29}
30
311;
32
33=encoding utf8
34
35=head1 NAME
36
37Data::Object::Struct
38
39=cut
40
41=head1 ABSTRACT
42
43Struct Class for Perl 5
44
45=cut
46
47=head1 SYNOPSIS
48
49  package main;
50
51  use Data::Object::Struct;
52
53  my $person = Data::Object::Struct->new(
54    fname => 'Aron',
55    lname => 'Nienow',
56    cname => 'Jacobs, Sawayn and Nienow'
57  );
58
59  # $person->fname # Aron
60  # $person->lname # Nienow
61  # $person->cname # Jacobs, Sawayn and Nienow
62
63  # $person->mname
64  # Error!
65
66  # $person->mname = 'Clifton'
67  # Error!
68
69  # $person->{mname} = 'Clifton'
70  # Error!
71
72=cut
73
74=head1 DESCRIPTION
75
76This package provides a class that creates struct-like objects which bundle
77attributes together, is immutable, and provides accessors, without having to
78write an explicit class.
79
80=cut
81
82=head1 INTEGRATES
83
84This package integrates behaviors from:
85
86L<Data::Object::Role::Buildable>
87
88L<Data::Object::Role::Immutable>
89
90L<Data::Object::Role::Proxyable>
91
92=cut
93
94=head1 AUTHOR
95
96Al Newkirk, C<awncorp@cpan.org>
97
98=head1 LICENSE
99
100Copyright (C) 2011-2019, Al Newkirk, et al.
101
102This is free software; you can redistribute it and/or modify it under the terms
103of the The Apache License, Version 2.0, as elucidated in the L<"license
104file"|https://github.com/iamalnewkirk/data-object-struct/blob/master/LICENSE>.
105
106=head1 PROJECT
107
108L<Wiki|https://github.com/iamalnewkirk/data-object-struct/wiki>
109
110L<Project|https://github.com/iamalnewkirk/data-object-struct>
111
112L<Initiatives|https://github.com/iamalnewkirk/data-object-struct/projects>
113
114L<Milestones|https://github.com/iamalnewkirk/data-object-struct/milestones>
115
116L<Contributing|https://github.com/iamalnewkirk/data-object-struct/blob/master/CONTRIBUTE.md>
117
118L<Issues|https://github.com/iamalnewkirk/data-object-struct/issues>
119
120=cut
121