File Coverage

blib/lib/Net/OAuth2/Scheme.pm
Criterion Covered Total %
statement 12 31 38.7
branch 2 6 33.3
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 19 46 41.3


line stmt bran cond sub pod time code
1 3     3   45160 use warnings;
  3         5  
  3         95  
2 3     3   11 use strict;
  3         3  
  3         110  
3              
4             package Net::OAuth2::Scheme;
5             BEGIN {
6 3     3   943 $Net::OAuth2::Scheme::VERSION = '0.020002_099';
7             }
8             # ABSTRACT: Token scheme definition framework for OAuth 2.0
9              
10             our $Factory_Class = 'Net::OAuth2::Scheme::Factory';
11              
12             # some inside_out object support
13             # ours are a little weird because our object data are
14             # the option values that live in closures
15             # so the only thing we put here are the methods
16             # which can vary wildly depending on context
17             #
18             my %methods_hash = (); # class -> methodname -> tag -> closure
19             my %next_tag = ();
20             my %free_tags = ();
21             our $Temp;
22              
23             sub new {
24             # I am still not convinced there will ever be subclasses;
25             # makes much more sense to subclass or replace the factory;
26             # but now that I've said that, someone will find an excuse,
27             # so we'll just follow the paradigm anyway...
28 2     2 1 3781 my $class = shift;
29              
30 2         2 my $factory_class;
31 2 50       14 if ($_[0] eq 'factory') {
32 0         0 (undef, $factory_class) = splice(@_,0,2); # shift shift
33             # Yes, this means (factory => classname) has to be first.
34             # Cope.
35             }
36             else {
37 2         4 $factory_class = $Factory_Class;
38             }
39 2 50       99 eval "require $factory_class" or die $@;
40 0           my $factory = $factory_class->new(@_);
41              
42             # start the cascade of methods being implemented
43 0           $factory->uses('root');
44              
45             # build the object, make sure the method definitions are there
46             my $tag =
47             pop @{$free_tags{$class} ||= []}
48 0   0       || ($next_tag{$class} ||= 'a')++;
49 0           for my $method ($factory->all_exports) {
50 0 0         unless ($methods_hash{$class}{$method}) {
51             # mom, dad, don't touch it, it's EVIL
52             # but we stay completely strict... hahahahahaha
53 0           eval <
54             package ${class};
55             my \%${method} = ();
56             sub ${method} {
57             my \$self = shift;
58             return \$${method}\{\$\$self}->(\@_);
59             }
60 0           \$@{[ __PACKAGE__ . '::Temp']} = \\\%${method};
61             END
62 0           $methods_hash{$class}{$method} = $Temp;
63 0           undef $Temp;
64             }
65 0           $methods_hash{$class}{$method}{$tag} = $factory->uses($method);
66             }
67 0           return bless \ $tag, $class;
68             }
69              
70             sub DESTROY {
71 0     0     my $self = shift;
72 0           my $class = ref($self);
73 0           for my $hash (values %{$methods_hash{$class}}) {
  0            
74 0           delete $hash->{$$self};
75             }
76 0           push @{$free_tags{$class}}, $$self;
  0            
77             }
78              
79             1;
80              
81              
82             __END__