{
    "mode": "perldoc",
    "parameter": "Type::Tiny::Duck",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3ADuck/json",
    "generated": "2026-10-08T14:09:45Z",
    "synopsis": "Using via Types::Standard:\npackage Logger {\nuse Moo;\nuse Types::Standard qw( HasMethods Bool );\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => HasMethods[ 'print' ] );\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}\nUsing Type::Tiny::Duck's export feature:\npackage Logger {\nuse Moo;\nuse Types::Standard qw( Bool );\nuse Type::Tiny::Duck Printable => [ 'print' ];\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => Printable );\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}\nUsing Type::Tiny::Duck's object-oriented interface:\npackage Logger {\nuse Moo;\nuse Types::Standard qw( Bool );\nuse Type::Tiny::Duck;\nmy $Printable = Type::Type::Duck->new(\nname    => 'Printable',\nmethods => [ 'print' ],\n);\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => $Printable );\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}",
    "sections": {
        "NAME": {
            "content": "Type::Tiny::Duck - type constraints based on the \"can\" method\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Using via Types::Standard:\n\npackage Logger {\nuse Moo;\nuse Types::Standard qw( HasMethods Bool );\n\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => HasMethods[ 'print' ] );\n\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\n\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}\n\nUsing Type::Tiny::Duck's export feature:\n\npackage Logger {\nuse Moo;\nuse Types::Standard qw( Bool );\nuse Type::Tiny::Duck Printable => [ 'print' ];\n\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => Printable );\n\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\n\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}\n\nUsing Type::Tiny::Duck's object-oriented interface:\n\npackage Logger {\nuse Moo;\nuse Types::Standard qw( Bool );\nuse Type::Tiny::Duck;\n\nmy $Printable = Type::Type::Duck->new(\nname    => 'Printable',\nmethods => [ 'print' ],\n);\n\nhas debugging => ( is => 'rw', isa => Bool, default => 0 );\nhas output    => ( is => 'ro', isa => $Printable );\n\nsub warn {\nmy ( $self, $message ) = @;\n$self->output->print( \"[WARNING] $message\\n\" );\n}\n\nsub debug {\nmy ( $self, $message ) = @;\n$self->output->print( \"[DEBUG] $message\\n\" ) if $self->debugging;\n}\n}\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Type constraints of the general form \"{ $->can(\"method\") }\".\n\nThe name refers to the saying, \"If it looks like a duck, swims like a duck, and quacks like a\nduck, then it probably is a duck\". Duck typing can be a more flexible way of testing objects\nthan relying on \"isa\", as it allows people to easily substitute mock objects.\n\nThis package inherits from Type::Tiny; see that for most documentation. Major differences are\nlisted below:\n",
            "subsections": [
                {
                    "name": "Attributes",
                    "content": "\"methods\"\nAn arrayref of method names.\n\n\"constraint\"\nUnlike Type::Tiny, you *cannot* pass a constraint coderef to the constructor. Instead rely\non the default.\n\n\"inlined\"\nUnlike Type::Tiny, you *cannot* pass an inlining coderef to the constructor. Instead rely on\nthe default.\n\n\"parent\"\nParent is always Types::Standard::Object, and cannot be passed to the constructor.\n"
                },
                {
                    "name": "Methods",
                    "content": ""
                },
                {
                    "name": "stringifies_to",
                    "content": "See Type::Tiny::ConstrainedObject.\n"
                },
                {
                    "name": "numifies_to",
                    "content": "See Type::Tiny::ConstrainedObject.\n\n\"withattributevalues($attr1 => $constraint1, ...)\"\nSee Type::Tiny::ConstrainedObject.\n"
                },
                {
                    "name": "Exports",
                    "content": "Type::Tiny::Duck can be used as an exporter.\n\nuse Type::Tiny::Duck HttpClient => [ 'get', 'post' ];\n\nThis will export the following functions into your namespace:\n\n\"HttpClient\""
                },
                {
                    "name": "is_HttpClient",
                    "content": ""
                },
                {
                    "name": "assert_HttpClient",
                    "content": ""
                },
                {
                    "name": "to_HttpClient",
                    "content": "Multiple types can be exported at once:\n\nuse Type::Tiny::Duck (\nHttpClient   => [ 'get', 'post' ],\nFtpClient    => [ 'upload', 'download' ],\n);\n"
                }
            ]
        },
        "BUGS": {
            "content": "Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Type::Tiny::Manual.\n\nType::Tiny.\n\nMoose::Meta::TypeConstraint::DuckType.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nWITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        }
    },
    "summary": "Type::Tiny::Duck - type constraints based on the \"can\" method",
    "flags": [],
    "examples": [],
    "see_also": []
}