Object::eBay::Boolean - Represents a boolean return value


Object-eBay documentation Contained in the Object-eBay distribution.

Index


Code Index:

NAME

Top

Object::eBay::Boolean - Represents a boolean return value

SYNOPSIS

Top

    # assuming that $item is an Object::eBay::Item object
    my $private = $item->seller->is_feedback_private();

    # In string context, yields 'true' or 'false'
    print "Is the feedback private? $private\n";

    # In boolean context, yields 1 or 0
    if ($private) {
        print "Feedback is private\n";
    }
    else {
        print "Feedback is public\n";
    }

DESCRIPTION

Top

Many of eBay's API calls return boolean (true/false) values. An Object::eBay::Boolean object represents this boolean return value in a context-aware way. In boolean context, the value is simply a boolean value as expected. In string context, the value is eBay's literal 'true' or 'false' value.

METHODS

Top

true

A class method that returns a new Object::eBay::Boolean object representing true.

false

A class method that returns a new Object::eBay::Boolean object representing false.

as_boolean

This method implements the boolean context. Namely

    if ( $x->as_boolean() ) { ... }

is the same as

    if ($x) { ... }

as_string

This method implements the string context. Namely

    print "Example: " . $x->as_string() . "\n";

is the same as

    print "Example: $x\n";

DIAGNOSTICS

Top

Invalid boolean value '%s'

If an Object::eBay::Boolean object is constructed with a value other than 'true' or 'false', this exception is thrown. Seeing this exception most likely indicates an error (or change) in eBay's XML response.

CONFIGURATION AND ENVIRONMENT

Top

Object::eBay::Boolean requires no configuration files or environment variables.

DEPENDENCIES

Top

* Class::Std

INCOMPATIBILITIES

Top

None known.

BUGS AND LIMITATIONS

Top

Please report any bugs or feature requests to bug-object-ebay at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object-eBay. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Object::eBay;

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Object-eBay

* CPAN Ratings

http://cpanratings.perl.org/d/Object-eBay

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Object-eBay

* Search CPAN

http://search.cpan.org/dist/Object-eBay

ACKNOWLEDGEMENTS

Top

AUTHOR

Top

Michael Hendricks <michael@ndrix.org>

LICENSE AND COPYRIGHT

Top


Object-eBay documentation Contained in the Object-eBay distribution.

package Object::eBay::Boolean;
our $VERSION = '0.4.0';

use Class::Std; {
    use warnings;
    use strict;
    use Carp;

    my %value_for :ATTR( :get<value> );

    sub BUILD {
        my ($self, $ident, $args_ref) = @_;
        my $details = $args_ref->{object_details} || q{};
        croak "Invalid boolean value '$details'\n"
            unless $details eq 'true' || $details eq 'false';
        $value_for{$ident} = $details && $details eq 'true' ? 1 : 0;
    }

    sub as_string :STRINGIFY {
        my ($self) = @_;
        return $self->get_value() ? 'true' : 'false';
    }

    sub as_boolean :BOOLIFY {
        my ($self) = @_;
        return $self->get_value();
    }

    sub true  { shift->new({ object_details => 'true' })  }
    sub false { shift->new({ object_details => 'false' }) }
}

1;

__END__