{"id":17891341,"url":"https://github.com/cside/sub-inspector","last_synced_at":"2025-04-03T03:22:32.237Z","repository":{"id":3197426,"uuid":"4230611","full_name":"Cside/Sub-Inspector","owner":"Cside","description":"get infomation from coderef","archived":false,"fork":false,"pushed_at":"2013-06-05T12:22:51.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T17:23:21.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cside.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-05T01:15:07.000Z","updated_at":"2014-09-09T02:04:33.000Z","dependencies_parsed_at":"2022-09-18T01:20:39.942Z","dependency_job_id":null,"html_url":"https://github.com/Cside/Sub-Inspector","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cside%2FSub-Inspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cside%2FSub-Inspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cside%2FSub-Inspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cside%2FSub-Inspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cside","download_url":"https://codeload.github.com/Cside/Sub-Inspector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246928692,"owners_count":20856331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-28T14:16:39.847Z","updated_at":"2025-04-03T03:22:32.210Z","avatar_url":"https://github.com/Cside.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"package Sub::Inspector;\nuse 5.008_001;\nuse strict;\nuse warnings;\nuse B ();\nuse Carp ();\nour @CARP_NOT;\nuse attributes;\nuse Data::Dumper;\n\nour $VERSION = 'Y';\n\nsub new {\n    my ($class, $code) = @_;\n    _throw($code) unless ref($code) eq 'CODE';\n    bless +{ code =\u003e $code }, $class;\n}\n\nsub file { B::svref_2object(_code(@_))-\u003eGV-\u003eFILE }\nsub line { B::svref_2object(_code(@_))-\u003eGV-\u003eLINE }\nsub name { B::svref_2object(_code(@_))-\u003eGV-\u003eNAME }\n\nsub proto     { B::svref_2object(_code(@_))-\u003ePV }\nsub prototype { proto(@_) }\n\nsub attrs      { attributes::get(_code(@_)) }\nsub attributes { attrs(@_) }\n\nsub _throw {\n    local $Data::Dumper::Indent = 1;\n    local $Data::Dumper::Terse  = 1;\n    local @CARP_NOT = (__PACKAGE__);\n    Carp::croak \"argument isn't a subroutine reference: \" . Dumper($_[0]);\n}\n\nsub _code {\n    my ($stuff, $arg) = @_;\n    # instance method\n    if (ref($stuff) eq __PACKAGE__) {\n        return $stuff-\u003e{code};\n    # calss method\n    } elsif (defined($stuff) \u0026\u0026 $stuff eq __PACKAGE__) {\n        return $arg if (ref($arg) eq 'CODE');\n        _throw($arg);\n    }\n}\n\n1;\n__END__\n\n=head1 NAME\n\nSub::Inspector - get infomation (prototype, attributes, name, etc) from a subroutine reference\n\n=head1 SYNOPSIS\n\n    use Sub::Inspector;\n\n\n    # get file, line, name (oo interface)\n\n    use File::Spec;\n    my $code = File::Spec-\u003ecan('canonpath');\n    my $inspector = Sub::Inspector-\u003enew($code);\n\n    print $inspector-\u003efile; #=\u003e '/Users/Cside/perl5/ ... /File/Spec/Unix.pm'\n    print $inspector-\u003eline; #=\u003e 71\n    print $inspector-\u003ename; #=\u003e 'canonpath'\n\n    # class method interface\n\n    print Sub::Inspector-\u003efile($code); #=\u003e '/Users/Cside/perl5/ ... /File/Spec/Unix.pm'\n    print Sub::Inspector-\u003eline($code); #=\u003e 71\n    print Sub::Inspector-\u003ename($code); #=\u003e 'canonpath'\n\n\n    # get prototype\n\n    use Try::Tiny qw(try);\n\n    print Sub::Inspector-\u003eproto(\\\u0026try); #=\u003e '\u0026;@'\n\n\n    # get attributes\n\n    use AnyEvent::Handle;\n    my $code2 = AnyEvent::Handle-\u003ecan('rbuf');\n\n    print Sub::Inspector-\u003eattrs($code2); #=\u003e ('lvalue')\n\n=head1 DESCRIPTION\n\nThis module enable to get metadata (prototype, attributes, method name, etc) from a coderef.\nWe can get them by the buit-in module, B.pm. However, it is a bit difficult to memorize how to use it.\n\n=head1 Functions\n\nNOTE: You can call each method whether as instance method or as class method.\n\n=over\n\n=item $inspector-\u003efile\n\n=item $inspector-\u003eline\n\n=item $inspector-\u003ename\n\n=item $inspector-\u003eproto\n\nalias: prototype\n\n=item $inspector-\u003eattrs\n\nalias: attributes\n\n=back\n\n=head1 SEE ALSO\n\n=over\n\n=item L\u003cB\u003e\n\n=item L\u003cB::Deparser\u003e\n\n=back\n\n=head1 AUTHOR\n\nHiroki Honda (Cside) E\u003clt\u003ecside.story [at] gmail.comE\u003cgt\u003e\n\n=head1 LICENSE AND COPYRIGHT\n\nCopyright (c) Hiroki Honda.\n\nThis library is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself.\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcside%2Fsub-inspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcside%2Fsub-inspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcside%2Fsub-inspector/lists"}