Class::Struct::FIELDS

Class::Struct::FIELDS module combine Class::Struct, base and fields.
Download

Class::Struct::FIELDS Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • B. K. Oxley
  • Publisher web site:
  • http://search.cpan.org/~binkley/Class-Struct-FIELDS-1.1/FIELDS.pm

Class::Struct::FIELDS Tags


Class::Struct::FIELDS Description

Class::Struct::FIELDS module combine Class::Struct, base and fields. Class::Struct::FIELDS module combine Class::Struct, base and fields.SYNOPSIS(This page documents Class::Struct::FIELDS v.1.1.) use Class::Struct::FIELDS; # declare struct, based on fields, explicit class name: struct (CLASS_NAME => { ELEMENT_NAME => ELEMENT_TYPE, ... }); use Class::Struct::FIELDS; # declare struct, based on fields, explicit class name # with inheritance: struct (CLASS_NAME => , { ELEMENT_NAME => ELEMENT_TYPE, ... }); package CLASS_NAME; use Class::Struct::FIELDS; # declare struct, based on fields, implicit class name: struct (ELEMENT_NAME => ELEMENT_TYPE, ...); package CLASS_NAME; use Class::Struct::FIELDS; # declare struct, based on fields, implicit class name # with inheritance: struct (, ELEMENT_NAME => ELEMENT_TYPE, ...); package MyObj; use Class::Struct::FIELDS; # declare struct with four types of elements: struct (s => '$', a => '@', h => '%', x => '&', c => 'My_Other_Class'); $obj = new MyObj; # constructor # scalar type accessor: $element_value = $obj->s; # element value $obj->s ('new value'); # assign to element # array type accessor: $ary_ref = $obj->a; # reference to whole array $ary_element_value = $obj->a->; # array element value $ary_element_value = $obj->a (2); # same thing $obj->a-> = 'new value'; # assign to array element $obj->a (2, 'newer value'); # same thing # hash type accessor: $hash_ref = $obj->h; # reference to whole hash $hash_element_value = $obj->h->{x}; # hash element value $hash_element_value = $obj->h (x); # same thing $obj->h->{x} = 'new value'; # assign to hash element $obj->h (x, 'newer value'); # same thing # code type accessor: $code_ref = $obj->x; # reference to code $obj->x->(...); # call code $obj->x (sub {...}); # assign to element # regexp type accessor: $regexp = $obj->r; # reference to code $string =~ m/$obj->r/; # match regexp $obj->r (qr/ ... /); # assign to element # class type accessor: $element_value = $obj->c; # object reference $obj->c->method (...); # call method of object $obj->c (My_Other_Class::->new); # assign a new objectClass::Struct::FIELDS exports a single function, struct. Given a list of element names and types, and optionally a class name and/or an array reference of base classes, struct creates a Perl 5 class that implements a "struct-like" data structure with inheritance.The new class is given a constructor method, new, for creating struct objects.Each element in the struct data has an accessor method, which is used to assign to the element and to fetch its value. The default accessor can be overridden by declaring a sub of the same name in the package. (See Example 2.)Each element's type can be scalar, array, hash, code or class. Requirements: · Perl


Class::Struct::FIELDS Related Software