App-Test-Generator

 view release on metacpan or  search on metacpan

doc/SchemaExtractor.pm  view on Meta::CPAN

# App::Test::Generator::SchemaExtractor

Automatically extract test schemas from Perl modules for use with App::Test::Generator.

## Overview

This tool analyzes Perl modules and generates YAML schema files describing each method's parameters, types, and constraints. These schemas can then be used to automatically generate comprehensive test suites.

### Features

- **POD Parsing**: Extracts type information from method documentation
- **Code Analysis**: Detects validation patterns (length checks, ref checks, regex matching)
- **Signature Analysis**: Identifies parameter names from method signatures
- **Confidence Scoring**: Rates each schema as high/medium/low confidence
- **YAML Output**: Generates clean, editable schema files

## Installation

### Prerequisites

```bash
cpanm PPI
cpanm Pod::Simple
cpanm YAML::XS
```

### Install the Module

```bash
# Copy files to your project
cp SchemaExtractor.pm lib/App/Test/Generator/
cp extract-schemas bin/
chmod +x bin/extract-schemas
```

## Quick Start

### 1. Extract schemas from a module

```bash
perl bin/extract-schemas lib/MyModule.pm
```

This creates schema YAML files in `./schemas/` directory.

### 2. Review generated schemas

```bash
cat schemas/validate_email.yaml
```

Example output:
```yaml
---
confidence: high
input:
  email:
    max: 254
    min: 5
    matches: /^[^@]+@[^@]+\.[^@]+$/
    optional: 0
    type: string
method: validate_email
notes: []
```

### 3. Edit schemas as needed

Low confidence schemas may need manual correction:

```yaml
---
confidence: low
input:
  thing:
    optional: 0
    type: string  # <- You might need to fix this
method: mysterious_method
notes:
  - 'thing: type unknown - please review'
```

### 4. Use with Test Generator

```bash
fuzz-harness-generator -r schemas/validate_email.yaml
```

## Usage Examples

### Basic Usage

```bash



( run in 0.641 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )