™.. fields - Online Linux Manual PageSection : 3pm
Updated : 2009-06-30
Source : perl v5.10.1
Note : Perl Programmers Reference Guide
NAMEfields − compile−time class fields
SYNOPSIS {
package Foo;
use fields qw(foo bar _Foo_private);
sub new {
my Foo $self = shift;
unless (ref $self) {
$self = fields::new($self);
$self−>{_Foo_private} = "this is Foo's secret";
}
$self−>{foo} = 10;
$self−>{bar} = 20;
return $self;
}
}
my $var = Foo−>new;
$var−>{foo} = 42;
# this will generate an error
$var−>{zap} = 42;
# subclassing
{
package Bar;
use base 'Foo';
use fields qw(baz _Bar_private); # not shared with Foo
sub new {
my $class = shift;
my $self = fields::new($class);
$self−>SUPER::new(); # init base fields
$self−>{baz} = 10; # init own fields
$self−>{_Bar_private} = "this is Bar's secret";
return $self;
}
}
DESCRIPTIONThe \*(C`fields\*(C'\fR pragma enables compile-time verified class fields. NOTE: The current implementation keeps the declared fields in the %FIELDS hash of the calling package, but this may change in future versions. Do not update the %FIELDS hash directly, because it must be created at compile-time for it to be fully useful, as is done by this pragma. Only valid for perl before 5.9.0: If a typed lexical variable holding a reference is used to access a hash element and a package with the same name as the type has declared class fields using this pragma, then the operation is turned into an array access at compile time. The related \*(C`base\*(C'\fR pragma will combine fields from base classes and any fields declared using the \*(C`fields\*(C'\fR pragma. This enables field inheritance to work properly. Field names that start with an underscore character are made private to the class and are not visible to subclasses. Inherited fields can be overridden but will generate a warning if used together with the \*(C`\-w\*(C'\fR switch. Only valid for perls before 5.9.0: The effect of all this is that you can have objects with named fields which are as compact and as fast arrays to access. This only works as long as the objects are accessed through properly typed variables. If the objects are not typed, access is only checked at run time. The following functions are supported: new perl before 5.9.0: fields::new() creates and blesses a pseudo-hash comprised of the fields declared using the \*(C`fields\*(C'\fR pragma into the specified class. perl 5.9.0 and higher: fields::new() creates and blesses a restricted-hash comprised of the fields declared using the \*(C`fields\*(C'\fR pragma into the specified class. This function is usable with or without pseudo-hashes. It is the recommended way to construct a fields-based object. This makes it possible to write a constructor like this: package Critter::Sounds;
use fields qw(cat dog bird);
sub new {
my $self = shift;
$self = fields::new($self) unless ref $self;
$self−>{cat} = 'meow'; # scalar element
@$self{'dog','bird'} = ('bark','tweet'); # slice
return $self;
}
phash before perl 5.9.0: fields::phash() can be used to create and initialize a plain (unblessed) pseudo-hash. This function should always be used instead of creating pseudo-hashes directly. If the first argument is a reference to an array, the pseudo-hash will be created with keys from that array. If a second argument is supplied, it must also be a reference to an array whose elements will be used as the values. If the second array contains less elements than the first, the trailing elements of the pseudo-hash will not be initialized. This makes it particularly useful for creating a pseudo-hash from subroutine arguments: sub dogtag {
my $tag = fields::phash([qw(name rank ser_num)], [@_]);
}
fields::phash() also accepts a list of key-value pairs that will be used to construct the pseudo hash. Examples: my $tag = fields::phash(name => "Joe",
rank => "captain",
ser_num => 42);
my $pseudohash = fields::phash(%args);
perl 5.9.0 and higher: Pseudo-hashes have been removed from Perl as of 5.10. Consider using restricted hashes or fields::new() instead. Using fields::phash() will cause an error.
SEE ALSObase 0
Johanes Gumabo
Data Size : 13,471 byte
man-fields.3pmBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 6 / 168,020
Visitor ID : :
Visitor IP : 3.142.135.24 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|fields.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|fields.3pm|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|fields.3pm|41|br══─}─══|'br══─}─══
) (htmlprn|149|fields.3pm|41|'br══─}─══ |'br══─}─══
) (rof_nr_x|149|fields.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (rof_unit_scale_px|41|fields.3pm|51/52|F|.ie \nF ══─{─══. de IX
) (rof_if|19|fields.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (htmlprn|149|fields.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX
) (rof_escape_sequence|91|fields.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2"
) (parse_manual_page_|249|fields.3pm|57|══─}─══|.══─}─══
) (htmlprn|149|fields.3pm|57|.══─}─══ |.══─}─══
) (rof_escape_sequence|91|fields.3pm|175|\*(C`fields\*(C'\fR pragma enables compile-time verified class fields. |The \f(CW\*(C`fields\*(C'\fR pragma enables compile-time verified class fields.
) (rof_escape_sequence|91|fields.3pm|189|\*(C`base\*(C'\fR pragma will combine fields from base classes and any |The related \f(CW\*(C`base\*(C'\fR pragma will combine fields from base classes and any
) (rof_escape_sequence|91|fields.3pm|190|\*(C`fields\*(C'\fR pragma. This enables field |fields declared using the \f(CW\*(C`fields\*(C'\fR pragma. This enables field
) (rof_escape_sequence|91|fields.3pm|195|\*(C`\-w\*(C'\fR |overridden but will generate a warning if used together with the \f(CW\*(C`\-w\*(C'\fR
) (rof_escape_sequence|91|fields.3pm|210|\*(C`fields\*(C'\fR |pseudo-hash comprised of the fields declared using the \f(CW\*(C`fields\*(C'\fR
) (rof_escape_sequence|91|fields.3pm|214|\*(C`fields\*(C'\fR |restricted-hash comprised of the fields declared using the \f(CW\*(C`fields\*(C'\fR
)