# man > Mail::Message::Field::Flex

---
type: CommandReference
command: Mail::Message::Field::Flex
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `my $field = Mail::Message::Field::Flex->new($line);` — parse a raw header line
- `my $field = Mail::Message::Field::Flex->new('Subject' => 'Hello');` — simple field from name and body
- `$field->new('To' => $address_obj, [attributes => {charset => 'utf-8'}]);` — with attributes and options
- `$field->name;` — get field name
- `$field->body;` — get unfolded body
- `$field->string;` — full header line as string
- `$field->attribute('charset');` — access a single attribute
- `$field->toDate;` — interpret body as a date

## Name
Mail::Message::Field::Flex - one line of a message header

## Synopsis
perl
Mail::Message::Field::Flex->new( $line )
Mail::Message::Field::Flex->new( $name, $body, \@attributes, \%options )
Mail::Message::Field::Flex->new( $name, $objects, \@attributes, \%options )
## Options
Constructor options passed as a hash or array reference after the body/objects:

- `attributes => \@pairs` — key-value attributes (alternative to flat list)
- `comment => $string` — pre-formatted comment string
- `log => $level` — log level (default `'WARNINGS'`)
- `trace => $level` — trace level (default `'WARNINGS'`)

## Examples
perl
use Mail::Message::Field::Flex;

# From a raw header line
my $field = Mail::Message::Field::Flex->new("Subject: =?utf-8?Q?Hello_World?=\n");

# From components with attributes
my $from = Mail::Message::Field::Flex->new(
    'From',
    'user@example.com',
    [ charset => 'utf-8', lang => 'en' ],
    { log => 'DEBUG' }
);

print $from->name;          # 'From'
print $from->body;          # 'user@example.com'
print $from->attribute('charset'); # 'utf-8'
## See Also
- [Mail::Message::Field](http://localhost/phpMan.php/perldoc/Mail%3A%3AMessage%3A%3AField/markdown) — base class
- [Mail::Message::Field::Fast](http://localhost/phpMan.php/perldoc/Mail%3A%3AMessage%3A%3AField%3A%3AFast/markdown) — faster alternative
- [Mail::Reporter](http://localhost/phpMan.php/perldoc/Mail%3A%3AReporter/markdown) — error handling base