```{index} single: putstate_text; Digest::SHA function ``` ```{index} single: Digest::SHA::putstate_text; Perl function ``` # putstate_text Construct or restore a `Digest::SHA` object from a text state string. Accepts the text produced by `getstate` or `dump` and either: - As a **class method** (`Digest::SHA->putstate($text)`), returns a new object with algorithm and state taken from the string. - As an **instance method** (`$sha->putstate($text)`), rewrites the receiver in place, switching algorithm if the string asks for a different one. The algorithm is read from the text, so — unlike `_putstate` — you do not need to preconfigure the object with the correct algorithm. ## Synopsis ```perl my $sha = Digest::SHA->putstate($text); $sha->putstate($text); ``` ## What you get back A `Digest::SHA` object on success, `undef` if the string could not be parsed. ## Examples ```perl my $text = $other->getstate; my $sha = Digest::SHA->putstate($text); $sha->add($remaining_data); ``` ```perl ## Update an existing object from a state string: my $sha = Digest::SHA->new(256); $sha->putstate($text); ``` ```perl ## Invalid input returns undef: my $sha = Digest::SHA->putstate("garbage"); print defined $sha ? "ok" : "undef"; # undef ``` ## Edge cases - Unrecognised or truncated text returns `undef` rather than croaking. - When used as an instance method, the receiver's algorithm is overwritten by whatever the text specifies. ## Differences from upstream Fully compatible with upstream `Digest::SHA` {{ upstream.Digest_SHA }}. ## See also - `getstate` — produces the strings this method consumes. - `load` — convenience wrapper that reads the text from a file. - `_putstate` — binary-state counterpart for same-machine use.