---
name: "Badger::Data"
section: "3pm"
platform: "linux"
package: "libbadger-perl"
version: "0.16-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Badger::Data"
---

# Badger::Data(3pm)

base class for data object

## NOTE

This is being merged in from Template::TT3::Type.  The documentation still refers to the old name and relates to TT-specific use.

## NAME

Badger::Data - base class for data object

## SYNOPSIS

```
    # defining a subclass data type
    package Badger::Data::Thing;
    use base 'Badger::Data';

    our $METHODS = {
        wibble => \&wibble,
        wobble => \&wobble,
    };

    sub wibble {
        my $self = shift;
        # some wibble code...
    }

    sub wobble {
        my $self = shift;
        # some wobble code...
    }
```

## PLEASE NOTE

This module is being merged in from the prototype `"Template-TT3"` code. The implementation is subject to change and the documentation may be incomplete or incorrect in places.

## DESCRIPTION

The `"Badger::Data"` module implements a base class for the Badger::Data::Text, Badger::Data::List and Badger::Data::Hash data objects.

## METHODS

The following methods are defined in addition to those inherited from  Badger::Prototype and Badger::Base.

### init(\\%config)

Initialialisation method to handle any per-object initialisation. This is called by the **new()** method inherited from Badger::Base . In this base class, the method simply copies all items in the `$config` hash array into the `$self` object.

### clone()

Create a copy of the current object.

```
    my $clone = $object->clone();
```

Additional named parameters can be provided.  These are merged with the items defined in the parent object and passed to the cloned object's **init()** method.

```
    my $clone = $object->clone( g => 0.577 );
```

### methods()

Returns a reference to a hash array containing the content of the `$METHODS` package variable in the current class and any base classes.

```
    my $methods = $object->methods;
```

### method($name)

Returns a reference to a particular method from the hash reference  returned by the **methods()** method.

```
    my $method = $object->method('ref');
```

When called without any arguments, it returns a reference to the entire hash reference, as per **methods()**.

```
    my $method = $object->method->{ foo };
```

### metadata($name,$value)

This method provides access to an out-of-band (i.e. stored separately from the  data itself) hash array of metadata for the data item.  It returns a reference to a hash array when called without arguments.

```
    # fetch metadata hash and add an entry
    my $metadata = $data->metadata;
    $metadata->{ author } = 'Arthur Dent';

    # later... print the metadata
    print $data->metadata->{ author };
```

It returns the value of an item in the metadata hash when called with a single argument.

```
    print $data->metadata('author');
```

It sets the value of an item when called with two arguments.

```
    $data->metadata( author => 'Ford Prefect' );
```

### ref()

Returns the name of the object type, e.g. `"Template::TT3::Type"`, `"Template::TT3::Type::Text"`, Template::TT3::Type::List, etc., exactly as Perl's `"ref()"` function does.

### defined()

Returns a true/false (`1`/`0`) value to indicate if the target data is  defined.

### undefined()

Returns a true/false (`1`/`0`) value to indicate if the target data is  undefined.

### true()

Returns a true/false (`1`/`0`) value to indicate if the target data has  a true value (using by Perl's definition of what constitutes truth).

### false()

Returns a true/false (`1`/`0`) value to indicate if the target data has  a false value (using by Perl's definition of what constitutes truth).

## AUTHOR

Andy Wardley  \<http://wardley.org/\>

## COPYRIGHT

Copyright (C) 1996-2008 Andy Wardley.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

## SEE ALSO.

Template::TT3::Type::Text, Template::TT3::Type::List and Template::TT3::Type::Hash.
