Devel::PerlySense::Document::Api::Method - A method/sub


Devel-PerlySense documentation Contained in the Devel-PerlySense distribution.

Index


Code Index:

NAME

Top

Devel::PerlySense::Document::Api::Method - A method/sub

DESCRIPTION

Top

An Api::Method is a sub name and a location (possibly with a defined row, etc).

The Method has a documentation string and possibly POD.

PROPERTIES

Top

name

The method name

Default: "".

oLocationDocumented

A Document::Location object specifying where the method is documented, or undef if that is unknown.

Default: undef.

oDocument

A PerlySense::Document object specifying in which the method belongs to. This does not have to be the Document where it's declared.

Default: undef.

signature

Return doc string with the signature of the method, according to found documentation, usage, etc.

Readonly.

API METHODS

Top

new(oDocument, name)

Create new Method with $name belonging to $oDocument.

Set oLocationDocumented according to the found documentation.

signatureCall($oLocationDeclaration)

Return doc string with the call signature of the method, according to the $oLocationDeclaration, etc.

The call signature is the signature with a call arrow, either -> or \> .

AUTHOR

Top

Johan Lindström, <johanl[ÄT]DarSerMan.com>

BUGS

Top

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

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Devel-PerlySense documentation Contained in the Devel-PerlySense distribution.




use strict;
use warnings;

package Devel::PerlySense::Document::Api::Method;
our $VERSION = '0.01';





use Spiffy -Base;
use Carp;
use Data::Dumper;
use List::Util qw/ first /;

use Devel::PerlySense::Document::Api;
use Devel::PerlySense::Document::Location;





field "name" => "";





field "oLocationDocumented" => undef;





field "oDocument" => undef;





sub signature {

    my $signature = $self->name;
    my $nameMethod = $self->name;
    if(my $oLocation = $self->oLocationDocumented) {
        my @aTextPod = split(/\n/, $oLocation->rhProperty->{text});
        $signature =
                first( sub { /->\s*\b$nameMethod\b/ }, @aTextPod )
             || first( sub { /\b$nameMethod\b/      }, @aTextPod )
             || $signature;
    }

    $signature =~ s/ .* (\b$nameMethod\b) /$1/x;
    $signature =~ s/^ \s+ | \s* ; \s* $//gx;


    return $signature;
}





sub new(@) {
    my $pkg = shift;
    my (%p) = @_;

    my $self = bless {}, $pkg;
    $self->name($p{name}) or croak("Missing parameter name\n");
    $self->oDocument($p{oDocument}) or croak("Missing parameter oDocument\n");
    $self->oLocationDocumented(
        $self->oDocument->oPerlySense->oLocationMethodDocFromDocument(
            $self->oDocument,
            $self->name,
        )
    );

    return($self);
}





sub signatureCall {
    my ($oLocationDeclaration) = @_;
    my $signature = $self->signature;

    my $prefixCall = $self->oDocument->file eq $oLocationDeclaration->file ? '->' : '\>';

    return "$prefixCall$signature";
}





1;





__END__