Marc - Sebastian Lucksch > Dotiac-0.8 > Dotiac::DTL::Value

Download:
dotiac/Dotiac-0.8.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.8   Source   Latest Release: Dotiac-0.8_1

NAME ^

Dotiac::DTL::Value - Saves Dotiac::DTL-value.

SYNOPSIS ^

        my $v=Dajango::Template::Value->safe($data);
        if ($v->array) {
        }
        if ($v->number) {
        }
        print $v->content();

DESCRIPTION ^

Stores a value in an object, for use in filters. This marks the value safe for output or needs escaping.

Creation

new(VALUE, SAFE)

Creates a new Dajango::Template::Value with the contents VALUE. It will be marked as safe for output if SAFE is set to true.

        $value=Dajango::Template::Value->new($data,!$autoescape);

safe(VALUE)

Creates a new Dajango::Template::Value with the contents VALUE and marks it as safe for output.

        $value=Dajango::Template::Value->safe($data);

escape(VALUE)

Creates a new Dajango::Template::Value with the contents VALUE and marks it for escaping during output.

        $value=Dajango::Template::Value->escape($data);

Object methods.

These can be called on the created Dajango::Template::Value objects:

safe()

Returns true if this Dajango::Template::Value is safe for output

        if ($value->safe) {
                ...
        }

safe(1)

Marks this Dajango::Template::Value as safe without changing its contents.

        if ($time > 1)  { #Or something
                $value->safe(1);
        }

escape()

Returns true if this Dajango::Template::Value needs escaping for output

        if ($value->escape) {
                ...
        }

escape(1)

Marks this Dajango::Template::Value as unsafe without changing its contents.

        if ($time < 1)  { #Or something
                $value->escape(1);
        }

array()

Returns true if the contained value is an array.

        if ($value->array) {
                foreach (@{$value->content}) {
                        ...
                }
        }

hash()

Returns true if the contained value is a hash.

        if ($value->hash) {
                foreach (keys %{$value->content}) {
                        ...
                }
        }

object()

Returns true if the contained value is an object.

        if ($value->object) {
                die "Can't work with blessed variables";
        }

number()

Returns true if the contained value is a number.

        if ($value->number) {
                $value->set($value->content*20);
        }

undef()

Returns true if the contained value is not defined.

        if ($value->undef) {
                return Dotiac::DTL::Value->safe("Error");
        }

defined()

Returns true if the contained value is defined.

        if ($value->defined) {
                return $value;
        }
        return Dotiac::DTL::Value->safe("No Text found");

scalar()

Returns true if the contained value is defined and not a reference.

        if ($value->scalar) {
                return Dotiac::DTL::Value->safe(lc $value->content);
        }

true(OBJECT)

Returns a true Value if the object is true or filled (for array and hashrefs) and "" otherwise.

It will return the size of the referenced container of an arrayref or hashref.

It will also try to run the count() method of an object, if available.

Should be about the same result as Dotiac::DTL::Core's Dotiac::DTL::Conditional($var->content);

content()

Returns the contained value.

        print $value->content;

get()

Returns the contained value.

        print $value->get;

string()

Returns the contained value in a readable way and escapes the output if it's marked as unsafe.

Calls the string() method on a contained object that provides one.

        print $value->string;

repr()

Same as string()

Returns the contained value in a readable way, but don't escapes, even if the content is unsafe.

Calls the string() or the repr() method on a contained object that provides one of them.

This is useful if you need to escape the value yourself.

        print CGI::escape($value->repr()); #URLencode

pyrepr()

Same as repr(), but calls the repr() method on a contained object before it calls string();

stringnodefault()

Same as string(), but returns undef if the content is not defined.

set(VAR)

Changes the contained value without changing the safe/escape status.

If you want to apply some functions on the value, regardless of content or escape/safe status, use set() and repr():

        $value->set(uc $value->repr()); #Applies uc() on the content of $value, but doesn't change the output mode.

Returns itself, so you can write (in a filter):

        return $value->set("Foo") if $foo;

pyrep

Rekursive generator for pyrepr.

rep

Rekursive generator for repr.

str

Rekursive generator for string.

BUGS ^

If you find a bug, please report it.

SEE ALSO ^

http://www.djangoproject.com, Dotiac::DTL

LEGAL ^

Dotiac::DTL was built according to http://docs.djangoproject.com/en/dev/ref/templates/builtins/.

AUTHOR ^

Marc-Sebastian Lucksch

perl@marc-s.de

syntax highlighting: