# perldoc > Event::MakeMaker

---
type: CommandReference
command: Event::MakeMaker
mode: perldoc
section: 3
source: perldoc
---

## Quick Reference

- `use Event::MakeMaker qw(event_args); WriteMakefile(event_args(%args));` — Integrate C-level Event API into Makefile.PL
- `#include "EventAPI.h"` — Include in XS files
- `BOOT: I_EVENT_API("YourModule");` — Bootstrap Event API
- `GEventAPI->new_io(0,0);` — Create new IO watcher
- `GEventAPI->resume((pe_event*) watcher);` — Resume watcher
- `GEventAPI->start((pe_event*) watcher, 0);` — Start watcher (non-repeating)
- `GEventAPI->stop(watcher, 0);` — Stop watcher
- `GEventAPI->cancel(watcher);` — Cancel watcher

## Name

Event::MakeMaker — MakeMaker glue for the C-level Event API

## Synopsis

This is an advanced feature of Event.

## Description

For optimal performance, hook into Event at the C-level. You will need to modify your `Makefile.PL` and add code to your XS / C files.

## Warning

Hooking in at the C-level gives a huge performance gain but reduces the chance that your code will work unmodified with newer versions of Perl or Event. Set expectations accordingly.

## API Functions

### Event Manipulation

- `void (*queue)(pe_event *ev)` — Queue an event
- `void (*start)(pe_watcher *ev, int repeat)` — Start a watcher (repeat = 0 for one-shot)
- `void (*now)(pe_watcher *ev)` — Fire a watcher immediately
- `void (*stop)(pe_watcher *ev, int cancel_events)` — Stop a watcher, optionally cancel pending events
- `void (*cancel)(pe_watcher *ev)` — Cancel a watcher and remove from queue
- `void (*suspend)(pe_watcher *ev)` — Suspend a watcher
- `void (*resume)(pe_watcher *ev)` — Resume a watcher

### Constructors

All constructors optionally take a stash (HV*) and a template (SV*). Either or both can be `NULL`. The template should not be a reference.

- `pe_idle *(*new_idle)(HV*, SV*)` — Create a new idle watcher
- `pe_timer *(*new_timer)(HV*, SV*)` — Create a new timer watcher
- `pe_io *(*new_io)(HV*, SV*)` — Create a new I/O watcher
- `pe_var *(*new_var)(HV*, SV*)` — Create a new variable watcher
- `pe_signal *(*new_signal)(HV*, SV*)` — Create a new signal watcher

### Timeable (timer and idle)

- `void (*tstart)(pe_timeable *)` — Start a timeable watcher
- `void (*tstop)(pe_timeable *)` — Stop a timeable watcher

### Hooks

- `pe_qcallback *(*add_hook)(char *which, void *cb, void *ext_data)` — Add a hook to a named queue
- `void (*cancel_hook)(pe_qcallback *qcb)` — Cancel a previously added hook

### Stats

- `void (*install_stats)(pe_event_stats_vtbl *esvtbl)` — Install a statistics vtable
- `void (*collect_stats)(int yes)` — Enable/disable statistics collection
- `pe_ring *AllWatchers` — Pointer to ring of all watchers

### Typemap

- `SV *(*watcher_2sv)(pe_watcher *wa)` — Convert watcher to Perl SV
- `void *(*sv_2watcher)(SV *sv)` — Convert Perl SV to watcher pointer
- `SV *(*event_2sv)(pe_event *ev)` — Convert event to Perl SV
- `void *(*sv_2event)(SV *sv)` — Convert Perl SV to event pointer

## How To

### Makefile.PL

perl
use Event::MakeMaker qw(event_args);

# ... set up %args ...

WriteMakefile(event_args(%args));
### XS

c
#include "EventAPI.h"

BOOT:
  I_EVENT_API("YourModule");
### Example: Creating an I/O Watcher

c
static pe_io *X11_ev=0;

static void x_server_dispatch(void *ext_data)
{
    // ... dispatch handler ...
}

if (!X11_ev) {
    X11_ev = GEventAPI->new_io(0,0);
    X11_ev->poll = PE_R;
    sv_setpv(X11_ev->base.desc, "[X::Server]");
    X11_ev->base.callback = (void*) x_server_dispatch;
    X11_ev->base.ext_data = <whatever>;
    X11_ev->base.prio = PE_PRIO_NORMAL;
}
X11_ev->fd = x_fd;
GEventAPI->resume((pe_event*) X11_ev);
GEventAPI->start((pe_event*) X11_ev, 0);
### Creating a New Watcher Type

If you need a new type of watcher, send your problem analysis to the mailing list. The internal Event.h apparatus is not exported to minimize interdependencies.