|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Copyright (C) 2010, Yaroslav Korshak.  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Mojolicious::Plugin::LinkedContent;  | 
| 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
5
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
485522
 | 
 use warnings;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
78
 | 
    | 
| 
6
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
10
 | 
 use strict;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
92
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 require Mojo::URL;  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
10
 | 
 use base 'Mojolicious::Plugin';  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1087
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.07';  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my %defaults = (  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     'js_base'  => '/js',  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     'css_base' => '/css',  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 );  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $reverse = 0;  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 my $stashkey = '$linked_store';  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub register {  | 
| 
23
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
  
1
  
 | 
19035
 | 
     my ($self, $app, $params) = @_;  | 
| 
24
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     for (qw/js_base css_base/) {  | 
| 
25
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
         $self->{$_} =  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           defined($params->{$_}) ? delete($params->{$_}) : $defaults{$_};  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
     push @{$app->renderer->classes}, __PACKAGE__;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
    | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->renderer->add_helper(  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         require_js => sub {  | 
| 
33
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
3384
 | 
             $self->store_items('js', @_);  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
35
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
41
 | 
     );  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->renderer->add_helper(  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         require_css => sub {  | 
| 
38
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
1629
 | 
             $self->store_items('css', @_);  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
40
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
45
 | 
     );  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->renderer->add_helper(  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         include_css => sub {  | 
| 
43
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
46
 | 
             $self->include_css(@_);  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
45
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
     );  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     $app->renderer->add_helper(  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         include_js => sub {  | 
| 
48
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
60
 | 
             $self->include_js(@_);  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
50
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
45
 | 
     );  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
52
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
     $app->log->debug("Plugin " . __PACKAGE__ . " registred!");  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub store_items {  | 
| 
56
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
16
 | 
     my ($self, $target, $c, @items) = @_;  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
58
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my $upd;  | 
| 
59
 | 
6
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
24
 | 
     my $store = $c->stash($stashkey) || {};  | 
| 
60
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
95
 | 
     for ($reverse ? reverse(@items) : @items) {  | 
| 
61
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
22
 | 
         if (exists $store->{'garage'}{$target}{$_}) {  | 
| 
62
 | 
0
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             next unless $reverse;  | 
| 
63
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             my $x = $_;  | 
| 
64
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
             @{$store->{'box'}{$target}} = grep $_ ne $x,  | 
| 
 
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
65
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
               @{$store->{'box'}{$target}};  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
67
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
         $store->{'garage'}{$target}{$_} = 1;  | 
| 
68
 | 
6
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
         if (!$reverse) { push(@{$store->{'box'}{$target}}, $_) }  | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
    | 
| 
69
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         else           { unshift(@{$store->{'box'}{$target}}, $_); }  | 
| 
 
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
71
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
16
 | 
     $c->stash($stashkey => $store);  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
74
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub include_js {  | 
| 
75
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
  
1
  
 | 
6
 | 
     my $self = shift;  | 
| 
76
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my $c    = shift;  | 
| 
77
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     local $reverse = 1;  | 
| 
78
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
     $self->store_items('js', $c, @_) if @_;  | 
| 
79
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
     my $store = $c->stash($stashkey);  | 
| 
80
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
28
 | 
     return '' unless $store->{'box'}{'js'};  | 
| 
81
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my @ct;  | 
| 
82
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     for (@{$store->{'box'}{'js'}}) {  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
84
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
         $c->stash('$linked_item' => $self->_prepend_path($_, 'js_base'));  | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
86
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
403
 | 
         push @ct, $c->render_to_string(  | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             template => 'LinkedContent/js',  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             format   => 'html',  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             handler  => 'ep',  | 
| 
90
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # template_class is deprecated since Mojolicious 2.62  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # was removed at some point which broke my code.  | 
| 
93
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # But it'll live here for a while  | 
| 
94
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             template_class => __PACKAGE__  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         );  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
97
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4478
 | 
     $c->stash('$linked_item', undef);  | 
| 
98
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
110
 | 
     return join '', @ct;  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
101
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub include_css {  | 
| 
102
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
  
1
  
 | 
5
 | 
     my $self = shift;  | 
| 
103
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my $c    = shift;  | 
| 
104
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     local $reverse = 1;  | 
| 
105
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     $self->store_items('css', $c, @_) if @_;  | 
| 
106
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
     my $store = $c->stash($stashkey);  | 
| 
107
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
22
 | 
     return '' unless $store->{'box'}{'css'};  | 
| 
108
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     my @ct;  | 
| 
109
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     for (@{$store->{'box'}{'css'}}) {  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
    | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
111
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
         $c->stash('$linked_item' => $self->_prepend_path($_, 'css_base'));  | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
113
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
300
 | 
         push @ct, $c->render_to_string(  | 
| 
114
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             template => 'LinkedContent/css',  | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             format   => 'html',  | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             handler  => 'ep',  | 
| 
117
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
118
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # template_class is deprecated since Mojolicious 2.62  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # was removed at some point which broke my code.  | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             # But it'll live here for a while  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             template_class => __PACKAGE__  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         );  | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
124
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3010
 | 
     $c->stash('$linked_item', undef);  | 
| 
125
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
118
 | 
     return join '', @ct;  | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
128
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _prepend_path {  | 
| 
129
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
 
 | 
10
 | 
     my ($self, $path, $base) = @_;  | 
| 
130
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
131
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
33
 | 
     my $url = Mojo::URL->new($path);  | 
| 
132
 | 
6
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
1377
 | 
     if ($url->is_abs || $url->path->leading_slash) {  | 
| 
133
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
134
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         # Absolute path or absolute url returned as is  | 
| 
135
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
244
 | 
         return $path;  | 
| 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
138
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Basepath not defined  | 
| 
139
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
152
 | 
     return unless $self->{$base};  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
141
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Prepend path with base  | 
| 
142
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
     my $basepath = Mojo::Path->new($self->{$base});  | 
| 
143
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
     unshift @{$url->path->parts}, @{$basepath->parts};  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
    | 
| 
144
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Inherit leading slash from basepath  | 
| 
146
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
133
 | 
     $url->path->leading_slash($basepath->leading_slash);  | 
| 
147
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
148
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40
 | 
     return $url->to_string;  | 
| 
149
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
151
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
152
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
153
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __DATA__  |