---
name: "Mojo::Stateful"
section: "3pm"
platform: "linux"
package: "libmojolicious-perl"
version: "0.999926-1+squeeze2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/Mojo::Stateful"
---

# Mojo::Stateful(3pm)

Stateful Base Class

## NAME

Mojo::Stateful - Stateful Base Class

## SYNOPSIS

```
    use base 'Mojo::Stateful';
```

## DESCRIPTION

Mojo::Stateful is an abstract base class for state keeping objects.

## ATTRIBUTES

Mojo::Stateful implements the following attributes.

### "state\_cb"

```
   my $cb    = $stateful->state_cb;
   $stateful = $stateful->state_cb(sub {...});
```

Callback that will be invoked whenever the state of this object changes.

## METHODS

Mojo::Stateful inherits all methods from Mojo::Base and implements the following new ones.

### "done"

```
    $stateful = $stateful->done;
```

Shortcut for setting the current state to `"done"`.

### "error"

```
    my $message          = $stateful->error;
    my ($message, $code) = $stateful->error;
    $stateful            = $stateful->error('Parser error.');
    $stateful            = $stateful->error('Parser error.', 500);
```

Shortcut for setting the current state to `"error"` with `"code"` and `"message"`.

### "has\_error"

```
    my $has_error = $stateful->has_error;
```

Check if an error occured.

### "is\_done"

```
    my $done = $stateful->is_done;
```

Check if the state machine is `"done"`.

### "is\_finished"

```
    my $finished = $stateful->is_finished;
```

Check if the state machine is finished, this includes the states `"done"`, `"done_with_leftovers"` and `"error"`.

### "is\_state"

```
    my $is_state = $stateful->is_state('writing');
    my $is_state = $stateful->is_state(qw/error reading writing/);
```

Check if the state machine is currently in a specific state.

### "state"

```
    my $state = $stateful->state;
    $stateful = $stateful->state('writing');
```

The current state.

## SEE ALSO

Mojolicious, Mojolicious::Guides, \<http://mojolicious.org\>.
